// Palindrom.cpp : Defines the entry point for the console application.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> bases = {29,31};
constexpr ll mod = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a;
cin >> a;
vector<ll> hf(bases.size()), hb(bases.size()), highs(bases.size());
for (int i = 0; i < bases.size(); i++) {
highs[i] = 1;
}
char x;
cin >> x;
int xx = x - 'a';
for (int i = 0; i < bases.size();i++) {
hf[i] = (xx)%mod;
}
for (int i=0;i<bases.size();i++) {
hb[i] = (xx * highs[i])%mod;
}
while (cin>>x) {
xx = x - 'a';
for (int i = 0; i < bases.size(); i++) {
highs[i] = (highs[i] * bases[i]) % mod;
hf[i] = (xx + (hf[i]*bases[i]) % mod) % mod;
hb[i] = (hb[i] + (xx*highs[i]) % mod) % mod;
}
}
bool chck = 1;
for (int i = 0; i < bases.size(); i++) {
if (hf[i] != hb[i]) chck = 0;
}
if (chck) {
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 40 41 42 43 44 45 46 47 48 | // Palindrom.cpp : Defines the entry point for the console application. // #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<ll> bases = {29,31}; constexpr ll mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a; cin >> a; vector<ll> hf(bases.size()), hb(bases.size()), highs(bases.size()); for (int i = 0; i < bases.size(); i++) { highs[i] = 1; } char x; cin >> x; int xx = x - 'a'; for (int i = 0; i < bases.size();i++) { hf[i] = (xx)%mod; } for (int i=0;i<bases.size();i++) { hb[i] = (xx * highs[i])%mod; } while (cin>>x) { xx = x - 'a'; for (int i = 0; i < bases.size(); i++) { highs[i] = (highs[i] * bases[i]) % mod; hf[i] = (xx + (hf[i]*bases[i]) % mod) % mod; hb[i] = (hb[i] + (xx*highs[i]) % mod) % mod; } } bool chck = 1; for (int i = 0; i < bases.size(); i++) { if (hf[i] != hb[i]) chck = 0; } if (chck) { cout << "TAK" << endl; } else { cout << "NIE" << endl; } return 0; } |
English