#include <iostream> #include <string> using namespace std; int main() { short zadania[102][3]; for (int x = 1; x < 102; x++) { for (int y = 0; y < 3; y++) { zadania[x][y] = 0; } } short amount; cin >> amount; for (int i = 0; i < amount; i++) { string napis; cin >> napis; switch (napis[napis.length() - 1]) { case 'A': { zadania[stoi(napis)][0]++; break; } case 'B': { zadania[stoi(napis)][1]++; break; } case 'C': { zadania[stoi(napis)][2]++; break; } } } int i; for (i = 101; i >= 0; i--) { bool yes = false; for (int z = 0; z < 3; z++) { if (zadania[i][z] >= 2) { if (!yes && z != 0) { cout << "NIE"; return 0; } yes = true; } else if (yes) { cout << "NIE"; return 0; } } if (yes) break; } for (; i >= 1; i--) { bool yes = false; for (int z = 0; z < 3; z++) { if (zadania[i][z] >= 1) { if (!yes && z != 0) { cout << "NIE"; return 0; } yes = true; } else if (yes) { cout << "NIE"; return 0; } } } cout << "TAK"; }
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <iostream> #include <string> using namespace std; int main() { short zadania[102][3]; for (int x = 1; x < 102; x++) { for (int y = 0; y < 3; y++) { zadania[x][y] = 0; } } short amount; cin >> amount; for (int i = 0; i < amount; i++) { string napis; cin >> napis; switch (napis[napis.length() - 1]) { case 'A': { zadania[stoi(napis)][0]++; break; } case 'B': { zadania[stoi(napis)][1]++; break; } case 'C': { zadania[stoi(napis)][2]++; break; } } } int i; for (i = 101; i >= 0; i--) { bool yes = false; for (int z = 0; z < 3; z++) { if (zadania[i][z] >= 2) { if (!yes && z != 0) { cout << "NIE"; return 0; } yes = true; } else if (yes) { cout << "NIE"; return 0; } } if (yes) break; } for (; i >= 1; i--) { bool yes = false; for (int z = 0; z < 3; z++) { if (zadania[i][z] >= 1) { if (!yes && z != 0) { cout << "NIE"; return 0; } yes = true; } else if (yes) { cout << "NIE"; return 0; } } } cout << "TAK"; } |