#include <iostream> using namespace std; int main() { int n; cin>>n; char cc; long long h1 = 0, h2 = 0, h3, h4; long long k = 1; long long p1 = 67, p2 = 1000000009; while(cin>>cc) { long long c = (long long)cc; //cout<<c<<' '<<k<<endl; h1 = (h1 + c * k) % p2; h2 = (h2 * p1 + c) % p2; //cout<<h1<<' '<<h2<<endl; k = (k * p1) % p2; } if (h1 == h2) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> using namespace std; int main() { int n; cin>>n; char cc; long long h1 = 0, h2 = 0, h3, h4; long long k = 1; long long p1 = 67, p2 = 1000000009; while(cin>>cc) { long long c = (long long)cc; //cout<<c<<' '<<k<<endl; h1 = (h1 + c * k) % p2; h2 = (h2 * p1 + c) % p2; //cout<<h1<<' '<<h2<<endl; k = (k * p1) % p2; } if (h1 == h2) cout<<"TAK"<<endl; else cout<<"NIE"<<endl; } |