#include <iostream>
using namespace std;
typedef long long ll;
const ll P = 211LL;
const ll Q = 1000000009LL;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
char c;
ll big_endian = 0, little_endian = 0;
ll curr_P = 1;
ll new_addition;
while(cin >> c) {
big_endian *= P;
big_endian %= Q;
big_endian += c - 'a';
big_endian %= Q;
new_addition = (c - 'a') * curr_P;
new_addition %= Q;
little_endian += new_addition;
little_endian %= Q;
curr_P *= P;
curr_P %= Q;
}
cout << (big_endian == little_endian ? "TAK" : "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 | #include <iostream> using namespace std; typedef long long ll; const ll P = 211LL; const ll Q = 1000000009LL; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; char c; ll big_endian = 0, little_endian = 0; ll curr_P = 1; ll new_addition; while(cin >> c) { big_endian *= P; big_endian %= Q; big_endian += c - 'a'; big_endian %= Q; new_addition = (c - 'a') * curr_P; new_addition %= Q; little_endian += new_addition; little_endian %= Q; curr_P *= P; curr_P %= Q; } cout << (big_endian == little_endian ? "TAK" : "NIE") << endl; return 0; } |
English