#include<bits/stdc++.h>
using namespace std;
const int p = 37;
const long long M = 1e15+7;
int main()
{
int n;
cin >> n;
long long w=0,q=0;
char a;
long long pot = 1;
while(cin >> a)
{
int s = a-'a'+1;
w=w*p;
w+=s;
w=w%M;
q+=pot*s;
q=q%M;
pot=(pot*p)%M;
}
if(q==w)cout << "TAK";
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 | #include<bits/stdc++.h> using namespace std; const int p = 37; const long long M = 1e15+7; int main() { int n; cin >> n; long long w=0,q=0; char a; long long pot = 1; while(cin >> a) { int s = a-'a'+1; w=w*p; w+=s; w=w%M; q+=pot*s; q=q%M; pot=(pot*p)%M; } if(q==w)cout << "TAK"; else cout << "NIE"; return 0; } |
English