#include <cstdio> using namespace std; long long MOD = 1e9+7; long long h1, h2; long long p = 31; long long pn = 1; int main() { int n; scanf("%d ", &n); char c; while(true) { if( scanf("%c", &c) != 1 ) break; if(c == '\n') break; h1 *= p; h1 += c; h1 %= MOD; h2 += pn*c; h2 %= MOD; pn *= p; pn %= MOD; } if(h1 == h2) printf("TAK\n"); else printf("NIE\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 | #include <cstdio> using namespace std; long long MOD = 1e9+7; long long h1, h2; long long p = 31; long long pn = 1; int main() { int n; scanf("%d ", &n); char c; while(true) { if( scanf("%c", &c) != 1 ) break; if(c == '\n') break; h1 *= p; h1 += c; h1 %= MOD; h2 += pn*c; h2 %= MOD; pn *= p; pn %= MOD; } if(h1 == h2) printf("TAK\n"); else printf("NIE\n"); return 0; } |