#include <bits/stdc++.h> using namespace std; #define P 29 #define M 1896540827 char c; long long n,p=1,a,b,d; int main() { scanf("%lld\n",&n); while (true) { scanf("%c",&c); if (c=='\n') {break;} a=c-96; b+=(a*p)%M; b%=M; p*=P; p%=M; d*=P; d%=M; d+=a; d%=M; } if (b==d) { 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 | #include <bits/stdc++.h> using namespace std; #define P 29 #define M 1896540827 char c; long long n,p=1,a,b,d; int main() { scanf("%lld\n",&n); while (true) { scanf("%c",&c); if (c=='\n') {break;} a=c-96; b+=(a*p)%M; b%=M; p*=P; p%=M; d*=P; d%=M; d+=a; d%=M; } if (b==d) { printf("TAK\n"); } else { printf("NIE\n"); } return 0; } |