// The "ZAB" task #include <iostream> #include <vector> using namespace std; int readLetterPosition(); int main(){ int n; cin >> n; vector<vector<int>> activeChildToys(2, vector<int>(26)); vector<vector<int>> passiveChildToys(2, vector<int>(26)); for (int i = 0; i < n; ++i){ ++activeChildToys[i%2][readLetterPosition()]; } for (int i = 0; i < n; ++i) { int letterPosition = readLetterPosition(); int parityIndex = i%2; ++passiveChildToys[parityIndex][letterPosition]; if (passiveChildToys[parityIndex][letterPosition] > activeChildToys[parityIndex][letterPosition]){ cout << "NIE" << endl; return 0; } } cout << "TAK" << endl; return 0; } int readLetterPosition() { char letter; cin >> letter; // asciiOfSmallLetter - 97 = positionOfThisLetterInAlphabet return letter - 97; }
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 | // The "ZAB" task #include <iostream> #include <vector> using namespace std; int readLetterPosition(); int main(){ int n; cin >> n; vector<vector<int>> activeChildToys(2, vector<int>(26)); vector<vector<int>> passiveChildToys(2, vector<int>(26)); for (int i = 0; i < n; ++i){ ++activeChildToys[i%2][readLetterPosition()]; } for (int i = 0; i < n; ++i) { int letterPosition = readLetterPosition(); int parityIndex = i%2; ++passiveChildToys[parityIndex][letterPosition]; if (passiveChildToys[parityIndex][letterPosition] > activeChildToys[parityIndex][letterPosition]){ cout << "NIE" << endl; return 0; } } cout << "TAK" << endl; return 0; } int readLetterPosition() { char letter; cin >> letter; // asciiOfSmallLetter - 97 = positionOfThisLetterInAlphabet return letter - 97; } |