#include <bits/stdc++.h>
using namespace std;
int n,ind;
char c;
stack <bool> s;
unsigned long long wynik,wynik2;
unsigned long long fast(int i,int v){
unsigned long long w=1;
while(i>0){
s.push(i%2);
i/=2;
}
while(!s.empty()){
if(s.top()==1){
w=w*(w*31%1000000459)%1000000459;
}
else{
w=w*w%1000000459;
}
//cout<<w<<endl;
s.pop();
}
//cout<<w<<' '<<v<<endl;
return w*v%1000000459;
}
int main()
{
ios_base::sync_with_stdio(0);
cin>>n;
if(n>0){
for(int i=1; i<=n/2; i++){
cin>>c;
int x=c-'a'+1;
wynik=wynik*31%1000000459;
wynik+=x;
wynik%=1000000459;
}
if(n%2==1){
cin>>c;
}
for(int i=1; i<=n/2; i++){
cin>>c;
wynik2+=fast(i-1,c-'a'+1);
}
//cout<<wynik<<endl;
//cout<<wynik2<<endl;
if(wynik2==wynik){
cout<<"TAK"<<endl;
}
else{
cout<<"NIE"<<endl;
}
}
else{
while(cin>>c){
ind++;
int x=c-'a'+1;
wynik2+=fast(ind-1,x);
wynik=wynik*31%1000000459;
wynik+=x;
wynik%=1000000459;
//cout<<wynik<<' ';
//cout<<wynik2<<endl;
}
if(wynik2==wynik){
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 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #include <bits/stdc++.h> using namespace std; int n,ind; char c; stack <bool> s; unsigned long long wynik,wynik2; unsigned long long fast(int i,int v){ unsigned long long w=1; while(i>0){ s.push(i%2); i/=2; } while(!s.empty()){ if(s.top()==1){ w=w*(w*31%1000000459)%1000000459; } else{ w=w*w%1000000459; } //cout<<w<<endl; s.pop(); } //cout<<w<<' '<<v<<endl; return w*v%1000000459; } int main() { ios_base::sync_with_stdio(0); cin>>n; if(n>0){ for(int i=1; i<=n/2; i++){ cin>>c; int x=c-'a'+1; wynik=wynik*31%1000000459; wynik+=x; wynik%=1000000459; } if(n%2==1){ cin>>c; } for(int i=1; i<=n/2; i++){ cin>>c; wynik2+=fast(i-1,c-'a'+1); } //cout<<wynik<<endl; //cout<<wynik2<<endl; if(wynik2==wynik){ cout<<"TAK"<<endl; } else{ cout<<"NIE"<<endl; } } else{ while(cin>>c){ ind++; int x=c-'a'+1; wynik2+=fast(ind-1,x); wynik=wynik*31%1000000459; wynik+=x; wynik%=1000000459; //cout<<wynik<<' '; //cout<<wynik2<<endl; } if(wynik2==wynik){ cout<<"TAK"<<endl; } else{ cout<<"NIE"<<endl; } } } |
English