#include <algorithm> #include <iostream> #include <vector> using namespace std; uint32_t n, i; char toy; bool found; vector<vector<uint32_t>> pos(26, vector<uint32_t>(0)); vector<uint32_t> *tmp; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(i = 0; i < n; i++) { cin >> toy; pos[toy - 'a'].push_back(i); } for(i = 0; i < n; i++) { cin >> toy; found = false; for(uint32_t c : pos[toy - 'a']) { if((c-i) % 2 == 0) { found = true; tmp = &(pos[toy - 'a']); (*tmp).erase(remove((*tmp).begin(), (*tmp).end(), c), (*tmp).end()); break; } } if(!found) { 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 | #include <algorithm> #include <iostream> #include <vector> using namespace std; uint32_t n, i; char toy; bool found; vector<vector<uint32_t>> pos(26, vector<uint32_t>(0)); vector<uint32_t> *tmp; int main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(i = 0; i < n; i++) { cin >> toy; pos[toy - 'a'].push_back(i); } for(i = 0; i < n; i++) { cin >> toy; found = false; for(uint32_t c : pos[toy - 'a']) { if((c-i) % 2 == 0) { found = true; tmp = &(pos[toy - 'a']); (*tmp).erase(remove((*tmp).begin(), (*tmp).end(), c), (*tmp).end()); break; } } if(!found) { cout << "NIE\n"; return 0; } } cout << "TAK\n"; return 0; } |