#include<iostream> using namespace std; int r,h1,h2,p,w; char x; int main() { cin>>r; if(r!=0) { for(int i=0; i<r/2; i++) { cin>>x; p=1; w=x-'a'; for(int j=0; j<i; j++) { p*=32; p=p%1000000007; } h1+=(w*p)%1000000007; } if(r%2==1) { cin>>x; } for(int i=0; i<r/2; i++) { cin>>x; p=1; w=x-'a'; for(int j=i+1; j<r/2; j++) { p*=32; p=p%1000000007; } h2+=(w*p)%1000000007; } //cout<<h1<<" "<<h2<<" "; if(h1==h2) { cout<<"TAK"; }else{ cout<<"NIE"; } }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 50 51 52 53 54 55 56 57 58 | #include<iostream> using namespace std; int r,h1,h2,p,w; char x; int main() { cin>>r; if(r!=0) { for(int i=0; i<r/2; i++) { cin>>x; p=1; w=x-'a'; for(int j=0; j<i; j++) { p*=32; p=p%1000000007; } h1+=(w*p)%1000000007; } if(r%2==1) { cin>>x; } for(int i=0; i<r/2; i++) { cin>>x; p=1; w=x-'a'; for(int j=i+1; j<r/2; j++) { p*=32; p=p%1000000007; } h2+=(w*p)%1000000007; } //cout<<h1<<" "<<h2<<" "; if(h1==h2) { cout<<"TAK"; }else{ cout<<"NIE"; } }else{ cout<<"NIE"; } return 0; } |