#include <iostream> #include <cstdio> #include <stdio.h> using namespace std; const long long prime = 100000231; int conver(char c) { return int(c-97); } int main() { int n, x; cin >> n; char c; c = getchar(); while(c < 'a' || c > 'z') c=getchar(); unsigned long long start=0, finish=0, pot=1; do{ if(c<97 || c>122) break; x = conver(c); start = ((start*26)%prime + x)%prime; finish = ((x*pot)%prime + finish)%prime; pot = (pot*26)%prime; c = getchar(); //cout << start << " " << finish << endl; }while(c >= 'a' && c <= 'z'); if(start==finish) cout << "TAK" << endl; else cout << "NIE" << 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 | #include <iostream> #include <cstdio> #include <stdio.h> using namespace std; const long long prime = 100000231; int conver(char c) { return int(c-97); } int main() { int n, x; cin >> n; char c; c = getchar(); while(c < 'a' || c > 'z') c=getchar(); unsigned long long start=0, finish=0, pot=1; do{ if(c<97 || c>122) break; x = conver(c); start = ((start*26)%prime + x)%prime; finish = ((x*pot)%prime + finish)%prime; pot = (pot*26)%prime; c = getchar(); //cout << start << " " << finish << endl; }while(c >= 'a' && c <= 'z'); if(start==finish) cout << "TAK" << endl; else cout << "NIE" << endl; return 0; } |