#include <bits/stdc++.h> using namespace std; const long long mod = 1e9+7, P = 32; int main(){ int n; long long hp=0LL, hl=0LL, akp = 1LL; scanf("%d ",&n); while(true){ char z; scanf("%c",&z); if(z > 'z' || z < 'a') break; hp = ((hp*32LL + (z-'a'+1LL))%mod+mod)%mod; hl = ((hl + (z-'a'+1LL)*akp)%mod+mod)%mod; akp = (akp*32LL)%mod; } //printf("%d %d\n",hl, hp); if(hl == hp) puts("TAK"); else puts("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 | #include <bits/stdc++.h> using namespace std; const long long mod = 1e9+7, P = 32; int main(){ int n; long long hp=0LL, hl=0LL, akp = 1LL; scanf("%d ",&n); while(true){ char z; scanf("%c",&z); if(z > 'z' || z < 'a') break; hp = ((hp*32LL + (z-'a'+1LL))%mod+mod)%mod; hl = ((hl + (z-'a'+1LL)*akp)%mod+mod)%mod; akp = (akp*32LL)%mod; } //printf("%d %d\n",hl, hp); if(hl == hp) puts("TAK"); else puts("NIE"); return 0; } |