#include <bits/stdc++.h> using namespace std; typedef long long LL; const LL H = 7919; LL HH = 1; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; LL h1=0, h2=0; char s; while(cin>>s){ HH*=H; h1 += s*HH; h2 *= H; h2 += s*H; } if(h1 == h2) cout<<"TAK\n"; else cout<<"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; typedef long long LL; const LL H = 7919; LL HH = 1; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; LL h1=0, h2=0; char s; while(cin>>s){ HH*=H; h1 += s*HH; h2 *= H; h2 += s*H; } if(h1 == h2) cout<<"TAK\n"; else cout<<"NIE\n"; return 0; } |