#include <bits/stdc++.h> using namespace std; unsigned long long n,a1,a2,b1,b2,podstsystem=1, m = 98764321234,m2=2147483647,podstsystem2=1; char xd; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; while(cin>>xd) { a1 = (a1 * 28 + (xd-96))%m; b1 = (b1 + (xd-96) * podstsystem)%m; podstsystem *= 28; podstsystem %= m; a2 = (a2 * 30 + (xd-96))%m2; b2 = (b2 + (xd-96) * podstsystem2)%m2; podstsystem2 *= 30; podstsystem2 %= m2; } if(a1 == b1 && a2 == b2) cout<<"TAK"; else cout<<"NIE"; }
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 | #include <bits/stdc++.h> using namespace std; unsigned long long n,a1,a2,b1,b2,podstsystem=1, m = 98764321234,m2=2147483647,podstsystem2=1; char xd; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; while(cin>>xd) { a1 = (a1 * 28 + (xd-96))%m; b1 = (b1 + (xd-96) * podstsystem)%m; podstsystem *= 28; podstsystem %= m; a2 = (a2 * 30 + (xd-96))%m2; b2 = (b2 + (xd-96) * podstsystem2)%m2; podstsystem2 *= 30; podstsystem2 %= m2; } if(a1 == b1 && a2 == b2) cout<<"TAK"; else cout<<"NIE"; } |