#include <bits/stdc++.h> using namespace std; using LL = long long; const int MOD = 1e9 + 7; LL h1 = 0, h2 = 0; LL pot = 97; LL pot2 = 1; int main() { int n; scanf("%d", &n); getchar(); while (true) { char c = getchar(); if (!isalpha(c)) break; h1 = ((h1 * pot) % MOD + (LL)c) % MOD; h2 = (h2 + ((LL)c * pot2) % MOD) % MOD; pot2 *= pot; pot2 %= MOD; } if (h1 == h2) printf("TAK\n"); else printf("NIE\n"); }
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 | #include <bits/stdc++.h> using namespace std; using LL = long long; const int MOD = 1e9 + 7; LL h1 = 0, h2 = 0; LL pot = 97; LL pot2 = 1; int main() { int n; scanf("%d", &n); getchar(); while (true) { char c = getchar(); if (!isalpha(c)) break; h1 = ((h1 * pot) % MOD + (LL)c) % MOD; h2 = (h2 + ((LL)c * pot2) % MOD) % MOD; pot2 *= pot; pot2 %= MOD; } if (h1 == h2) printf("TAK\n"); else printf("NIE\n"); } |