#include <iostream>
#include <string>
#include <vector>
#include <cstdint>
#include <cassert>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
struct hash {
std::uint64_t h1 = 0, h2 = 0, I, C;
hash(std::uint64_t i) : I(i), C(i) { }
void add(char c) {
unsigned int q = c;
h1 = h1 * I + q;
h2 = h2 + q * C;
C = C * I;
}
bool correct() const {
return h1 * I == h2;
}
};
int main()
{
unsigned int ignore;
scanf("%d", &ignore);
std::vector<hash> hashes = {
#define Q(a) hash(a)
Q(3),
Q(4079),Q(4091),Q(4093),Q(4099),Q(4111),Q(4127),Q(4129),Q(4133),Q(4139),Q(4153),Q(4157),Q(4159),Q(4177),Q(4201),Q(4211),Q(4217),Q(4219),Q(4229),Q(4231),Q(4241),Q(4243),Q(4253),Q(4259),Q(4261),Q(4271)
#undef Q
};
for(;;) {
auto c = getchar();
if (c == EOF) break;
if (c <= ' ') continue;
for(auto &z : hashes) z.add(c);
}
bool succ = true;
for(auto &z : hashes) {
if (!z.correct()) {
succ = false;
break;
}
}
std::cout << (succ ? "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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <string> #include <vector> #include <cstdint> #include <cassert> #include <iomanip> #include <cstdlib> #include <cstdio> struct hash { std::uint64_t h1 = 0, h2 = 0, I, C; hash(std::uint64_t i) : I(i), C(i) { } void add(char c) { unsigned int q = c; h1 = h1 * I + q; h2 = h2 + q * C; C = C * I; } bool correct() const { return h1 * I == h2; } }; int main() { unsigned int ignore; scanf("%d", &ignore); std::vector<hash> hashes = { #define Q(a) hash(a) Q(3), Q(4079),Q(4091),Q(4093),Q(4099),Q(4111),Q(4127),Q(4129),Q(4133),Q(4139),Q(4153),Q(4157),Q(4159),Q(4177),Q(4201),Q(4211),Q(4217),Q(4219),Q(4229),Q(4231),Q(4241),Q(4243),Q(4253),Q(4259),Q(4261),Q(4271) #undef Q }; for(;;) { auto c = getchar(); if (c == EOF) break; if (c <= ' ') continue; for(auto &z : hashes) z.add(c); } bool succ = true; for(auto &z : hashes) { if (!z.correct()) { succ = false; break; } } std::cout << (succ ? "TAK" : "NIE"); return 0; } |
English