#include <iostream> using namespace std; int main() { int n; cin>>n; if(n==0){ long long int check[26]; for(int i=0; i<26; ++i) check[i]=0; int ile=-1; string s1, s2; char litera; while(cin>>litera){ ile++; if(ile<500000) s1+=litera; s2+=litera; if(ile>=500000) s2.erase(0,1); check[litera-'a']+=ile; } for(int i=0; i<26; ++i){ if(check[i]%ile!=0){ cout<<"NIE"<<endl; return 0; } } for(int i=0; i<500000; ++i){ if(s1[i]!=s2[499999-i]){ cout<<"NIE"<<endl; return 0; } } } else if(n<1000000){ string s; cin>>s; int k=n/2; for(int i=0; i<k; ++i){ if(s[i]!=s[n-i-1]){ cout<<"NIE"<<endl; return 0; } } } else{ int check[26]; for(int i=0; i<26; ++i) check[i]=0; string s; int pom=min(900000, n/2), npom; char litera; for(int i=0; i<pom; ++i){ cin>>litera; s+=litera; check[litera-'a']+=i; check[litera-'a']=check[litera-'a']%(n-1); } npom=pom+1; if(n%2==1){ cin>>litera; check[litera-'a']+=pom+1; check[litera-'a']=check[litera-'a']%(n-1); npom++; } for(int i=npom; i<n; ++i){ cin>>litera; if(n-i-1<=pom){ if(s[n-i-1]!=litera){ cout<<"NIE"<<endl; return 0; } check[litera-'a']+=i; check[litera-'a']=check[litera-'a']%(n-1); } } for(int i=0; i<26; ++i){ if(check[i]!=0){ cout<<"NIE"<<endl; return 0; } } } cout<<"TAK"<<endl; 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <iostream> using namespace std; int main() { int n; cin>>n; if(n==0){ long long int check[26]; for(int i=0; i<26; ++i) check[i]=0; int ile=-1; string s1, s2; char litera; while(cin>>litera){ ile++; if(ile<500000) s1+=litera; s2+=litera; if(ile>=500000) s2.erase(0,1); check[litera-'a']+=ile; } for(int i=0; i<26; ++i){ if(check[i]%ile!=0){ cout<<"NIE"<<endl; return 0; } } for(int i=0; i<500000; ++i){ if(s1[i]!=s2[499999-i]){ cout<<"NIE"<<endl; return 0; } } } else if(n<1000000){ string s; cin>>s; int k=n/2; for(int i=0; i<k; ++i){ if(s[i]!=s[n-i-1]){ cout<<"NIE"<<endl; return 0; } } } else{ int check[26]; for(int i=0; i<26; ++i) check[i]=0; string s; int pom=min(900000, n/2), npom; char litera; for(int i=0; i<pom; ++i){ cin>>litera; s+=litera; check[litera-'a']+=i; check[litera-'a']=check[litera-'a']%(n-1); } npom=pom+1; if(n%2==1){ cin>>litera; check[litera-'a']+=pom+1; check[litera-'a']=check[litera-'a']%(n-1); npom++; } for(int i=npom; i<n; ++i){ cin>>litera; if(n-i-1<=pom){ if(s[n-i-1]!=litera){ cout<<"NIE"<<endl; return 0; } check[litera-'a']+=i; check[litera-'a']=check[litera-'a']%(n-1); } } for(int i=0; i<26; ++i){ if(check[i]!=0){ cout<<"NIE"<<endl; return 0; } } } cout<<"TAK"<<endl; return 0; } |