#include <cstdio> using LL = long long; const int Mod = 1010101049; const int Base = 5981724; int main() { int ch; while ((ch = fgetc_unlocked(stdin)) != '\n') {} int hash_straight = 0, hash_rev = 0; int cur_exp = 1; while ((ch = fgetc_unlocked(stdin)) != '\n') { hash_straight = (hash_straight + (LL)cur_exp * ch) % Mod; hash_rev = ((LL)hash_rev * Base + ch) % Mod; cur_exp = ((LL)cur_exp * Base) % Mod; } printf(hash_straight == hash_rev ? "TAK\n" : "NIE\n"); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <cstdio> using LL = long long; const int Mod = 1010101049; const int Base = 5981724; int main() { int ch; while ((ch = fgetc_unlocked(stdin)) != '\n') {} int hash_straight = 0, hash_rev = 0; int cur_exp = 1; while ((ch = fgetc_unlocked(stdin)) != '\n') { hash_straight = (hash_straight + (LL)cur_exp * ch) % Mod; hash_rev = ((LL)hash_rev * Base + ch) % Mod; cur_exp = ((LL)cur_exp * Base) % Mod; } printf(hash_straight == hash_rev ? "TAK\n" : "NIE\n"); } |