#include <algorithm> #include <cassert> #include <iostream> #include <vector> #include <string> #include <memory> #include <cassert> #include <cstdio> #include <stdexcept> #include <iterator> #include <type_traits> #include <unordered_map> using ull = unsigned long long; using ll = long long; struct info { int odd = 0, even = 0; }; std::unordered_map<char, info> a, b; int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::string s_a, s_b; std::cin >> s_a >> s_b; for(int i = 0; i < n; ++i) { a[s_a[i]].odd += i % 2 != 0 ? 1 : 0; a[s_a[i]].even += i % 2 == 0 ? 1 : 0; b[s_b[i]].odd += i % 2 != 0 ? 1 : 0; b[s_b[i]].even += i % 2 == 0 ? 1 : 0; } for(const auto& x : a) { auto y = b.find(x.first); if(y == b.end() || x.second.odd != y->second.odd || x.second.even != y->second.even) { std::cout << "NIE"; return 0; } } for(const auto& x : b) { auto y = a.find(x.first); if(y == a.end() || x.second.odd != y->second.odd || x.second.even != y->second.even) { std::cout << "NIE"; return 0; } } std::cout << "TAK"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <algorithm> #include <cassert> #include <iostream> #include <vector> #include <string> #include <memory> #include <cassert> #include <cstdio> #include <stdexcept> #include <iterator> #include <type_traits> #include <unordered_map> using ull = unsigned long long; using ll = long long; struct info { int odd = 0, even = 0; }; std::unordered_map<char, info> a, b; int main() { std::ios::sync_with_stdio(false); int n; std::cin >> n; std::string s_a, s_b; std::cin >> s_a >> s_b; for(int i = 0; i < n; ++i) { a[s_a[i]].odd += i % 2 != 0 ? 1 : 0; a[s_a[i]].even += i % 2 == 0 ? 1 : 0; b[s_b[i]].odd += i % 2 != 0 ? 1 : 0; b[s_b[i]].even += i % 2 == 0 ? 1 : 0; } for(const auto& x : a) { auto y = b.find(x.first); if(y == b.end() || x.second.odd != y->second.odd || x.second.even != y->second.even) { std::cout << "NIE"; return 0; } } for(const auto& x : b) { auto y = a.find(x.first); if(y == a.end() || x.second.odd != y->second.odd || x.second.even != y->second.even) { std::cout << "NIE"; return 0; } } std::cout << "TAK"; return 0; } |