#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; i++) #define FORR(i, n) for (int i = 1; i <= n; i++) #define FORi(n) for (int i = 0; i < n; i++) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; if (n == 0) { string s; cin >> s; n = s.size(); for (int i = 0; i < n; i++) { if (s[i] != s[n - i - 1]) { cout << "NIE"; return 0; } } cout << "TAK"; return 0; } else { long long hash1 = 0, hash2 = 0; long long hash1a = 0, hash2a = 0; for (int i = 0; i < n; i++) { char a; cin >> a; hash1 += ((long long)a) * (i + 100 + 1); hash2 += ((long long)a) * (n + 100 - i); hash1a += ((long long)a) * (i + 2137 + 1); hash2a += ((long long)a) * (n + 2137 - i); } if (hash1 == hash2 && hash1a == hash2a) cout << "TAK"; else cout << "NIE"; } 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; #define FOR(i, n) for (int i = 0; i < n; i++) #define FORR(i, n) for (int i = 1; i <= n; i++) #define FORi(n) for (int i = 0; i < n; i++) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; if (n == 0) { string s; cin >> s; n = s.size(); for (int i = 0; i < n; i++) { if (s[i] != s[n - i - 1]) { cout << "NIE"; return 0; } } cout << "TAK"; return 0; } else { long long hash1 = 0, hash2 = 0; long long hash1a = 0, hash2a = 0; for (int i = 0; i < n; i++) { char a; cin >> a; hash1 += ((long long)a) * (i + 100 + 1); hash2 += ((long long)a) * (n + 100 - i); hash1a += ((long long)a) * (i + 2137 + 1); hash2a += ((long long)a) * (n + 2137 - i); } if (hash1 == hash2 && hash1a == hash2a) cout << "TAK"; else cout << "NIE"; } return 0; } |