#include <bits/stdc++.h> using namespace std; const long long Mod_1 = 1e9 + 7; const long long Mod_2 = 1e9 + 9; const long long Bas_1 = 31; const long long Bas_2 = 79; long long Fro_1, Fro_2; long long Bac_1, Bac_2; long long Exp_1 = 1, Exp_2 = 1; int main() { register char c = 0; while (c < 'a' || c > 'z') c = getc_unlocked(stdin); while ('a' <= c && c <= 'z') { Fro_1 = (Fro_1 * Bas_1 + (c - 'a' + 1)) % Mod_1; Fro_2 = (Fro_2 * Bas_2 + (c - 'a' + 1)) % Mod_2; Bac_1 = (Bac_1 + Exp_1 * (c - 'a' + 1)) % Mod_1; Bac_2 = (Bac_2 + Exp_2 * (c - 'a' + 1)) % Mod_2; Exp_1 = (Exp_1 * Bas_1) % Mod_1; Exp_2 = (Exp_2 * Bas_2) % Mod_2; c = getc_unlocked(stdin); } puts(Fro_1 == Bac_1 && Fro_2 == Bac_2 ? "TAK" : "NIE"); 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 | #include <bits/stdc++.h> using namespace std; const long long Mod_1 = 1e9 + 7; const long long Mod_2 = 1e9 + 9; const long long Bas_1 = 31; const long long Bas_2 = 79; long long Fro_1, Fro_2; long long Bac_1, Bac_2; long long Exp_1 = 1, Exp_2 = 1; int main() { register char c = 0; while (c < 'a' || c > 'z') c = getc_unlocked(stdin); while ('a' <= c && c <= 'z') { Fro_1 = (Fro_1 * Bas_1 + (c - 'a' + 1)) % Mod_1; Fro_2 = (Fro_2 * Bas_2 + (c - 'a' + 1)) % Mod_2; Bac_1 = (Bac_1 + Exp_1 * (c - 'a' + 1)) % Mod_1; Bac_2 = (Bac_2 + Exp_2 * (c - 'a' + 1)) % Mod_2; Exp_1 = (Exp_1 * Bas_1) % Mod_1; Exp_2 = (Exp_2 * Bas_2) % Mod_2; c = getc_unlocked(stdin); } puts(Fro_1 == Bac_1 && Fro_2 == Bac_2 ? "TAK" : "NIE"); return 0; } |