#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> tab1[27]; vector<int> tab2[27]; for(int i = 0; i < n; i++) { char c; scanf(" %c", &c); tab1[c - 'a'].push_back(i); } for(int i = 0; i < n; i++) { char c; scanf(" %c", &c); tab2[c - 'a'].push_back(i); } for(int i = 0; i < 27; i++) { int bip = 0, bjp = 0; if(tab1[i].size() == tab2[i].size()) { for(int j: tab1[i]) bip += j & 1; for(int j: tab2[i]) bjp += j & 1; if(bip != bjp) { cout << "NIE\n"; return 0; } } else { cout << "NIE\n"; return 0; } } cout << "TAK\n"; 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 | #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> tab1[27]; vector<int> tab2[27]; for(int i = 0; i < n; i++) { char c; scanf(" %c", &c); tab1[c - 'a'].push_back(i); } for(int i = 0; i < n; i++) { char c; scanf(" %c", &c); tab2[c - 'a'].push_back(i); } for(int i = 0; i < 27; i++) { int bip = 0, bjp = 0; if(tab1[i].size() == tab2[i].size()) { for(int j: tab1[i]) bip += j & 1; for(int j: tab2[i]) bjp += j & 1; if(bip != bjp) { cout << "NIE\n"; return 0; } } else { cout << "NIE\n"; return 0; } } cout << "TAK\n"; return 0; } |