From 4c191e5ec41356fae301934c0d4bd44dd90162e2 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 13 Jun 2022 00:26:34 +0800 Subject: [PATCH] C - awoo's Favorite Problem https://codeforces.com/contest/1697/submission/160353710 --- Codeforces/1697/C/C.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Codeforces/1697/C/C.cpp diff --git a/Codeforces/1697/C/C.cpp b/Codeforces/1697/C/C.cpp new file mode 100644 index 00000000..4a77402d --- /dev/null +++ b/Codeforces/1697/C/C.cpp @@ -0,0 +1,58 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +int q, n; +std::string s, t; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> q; + + while (q--) { + cin >> n >> s >> t; + + s = ' ' + s; + t = ' ' + t; + + int b = 1, c = 1; + bool flag = true; + for (int i = 1; i <= n; i++) { + b = std::max(b, i); + c = std::max(c, i); + + if (s[i] == 'a' && t[i] == 'c' || s[i] == 'c' && t[i] == 'a' || s[i] == 'c' && t[i] == 'b' || s[i] == 'c' && t[i] == 'a') { + flag = false; + + break; + } + + if (s[i] == t[i]) continue; + + if (s[i] == 'a' && t[i] == 'b') { + while (s[b] != 'b' && s[b] == 'a' && b + 1 <= n) b++; + std::swap(s[i], s[b]); + } + + if (s[i] == 'b' && t[i] == 'c') { + while (s[c] != 'c' && s[c] == 'b' && c + 1 <= n) c++; + std::swap(s[i], s[c]); + } + + if (s[i] != t[i]) { + flag = false; + + break; + } + } + + cout << (flag ? "YES" : "NO") << endl; + } + + return 0; +}