//Krzysztof Boryczka #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; const int inf=0x3f3f3f3f; const ll INF=0x3f3f3f3f3f3f3f3f; #define FOR(i, b, e) for(int i=b; i<=e; i++) #define FORD(i, b, e) for(int i=b; i>=e; i--) #define SIZE(x) ((int)(x).size()) #define pb push_back #define st first #define nd second #define sp ' ' #define ent '\n' #define WATCH(x) cout<<(#x)<<" is "<<(x)<<ent //END OF TEMPLATE const ll p=31; const ll x=-'a'+1; const ll mod=1e9+123; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll a, prefhasz=0, sufhasz=0, potp=1; char c; cin>>a; while(cin>>c){ prefhasz=(prefhasz*p+(c+x))%mod; sufhasz=(sufhasz+(c+x)*potp)%mod; potp=(potp*p)%mod; } if(prefhasz==sufhasz){ cout<<"TAK"<<ent; } else{ cout<<"NIE"<<ent; } 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 | //Krzysztof Boryczka #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; const int inf=0x3f3f3f3f; const ll INF=0x3f3f3f3f3f3f3f3f; #define FOR(i, b, e) for(int i=b; i<=e; i++) #define FORD(i, b, e) for(int i=b; i>=e; i--) #define SIZE(x) ((int)(x).size()) #define pb push_back #define st first #define nd second #define sp ' ' #define ent '\n' #define WATCH(x) cout<<(#x)<<" is "<<(x)<<ent //END OF TEMPLATE const ll p=31; const ll x=-'a'+1; const ll mod=1e9+123; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll a, prefhasz=0, sufhasz=0, potp=1; char c; cin>>a; while(cin>>c){ prefhasz=(prefhasz*p+(c+x))%mod; sufhasz=(sufhasz+(c+x)*potp)%mod; potp=(potp*p)%mod; } if(prefhasz==sufhasz){ cout<<"TAK"<<ent; } else{ cout<<"NIE"<<ent; } return 0; } |