#include <cstdio>
typedef long long LL;
const LL prime = 1e9+7;
const LL prime2 = 1500450271;
const LL b = 124477;
const LL b2 = 1291;
const int chunk_size = 1024;
char tb[chunk_size+1];
int main() {
LL hash1 = 0, hash12 = 0;
LL hash2 = 0, hash22 = 0;
LL pt = b, pt2 = b2;
int n;
int read = 0;
while(1) {
read = fread(tb, sizeof(char), chunk_size, stdin);
for(int i = 0; i < read; ++i) {
if(tb[i] < 'a' || tb[i] > 'z') continue;
hash1 += tb[i];
hash1 %= prime;
hash1 *= b;
hash1 %= prime;
hash2 += (pt*tb[i])%prime;
hash2 %= prime;
pt = (pt*b)%prime;
hash12 += tb[i];
hash12 %= prime2;
hash12 *= b2;
hash12 %= prime2;
hash22 += (pt2*tb[i])%prime2;
hash22 %= prime2;
pt2 = (pt2*b2)%prime2;
}
if(read < chunk_size) break;
}
printf(hash1 == hash2 && hash12 == hash22 ? "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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <cstdio> typedef long long LL; const LL prime = 1e9+7; const LL prime2 = 1500450271; const LL b = 124477; const LL b2 = 1291; const int chunk_size = 1024; char tb[chunk_size+1]; int main() { LL hash1 = 0, hash12 = 0; LL hash2 = 0, hash22 = 0; LL pt = b, pt2 = b2; int n; int read = 0; while(1) { read = fread(tb, sizeof(char), chunk_size, stdin); for(int i = 0; i < read; ++i) { if(tb[i] < 'a' || tb[i] > 'z') continue; hash1 += tb[i]; hash1 %= prime; hash1 *= b; hash1 %= prime; hash2 += (pt*tb[i])%prime; hash2 %= prime; pt = (pt*b)%prime; hash12 += tb[i]; hash12 %= prime2; hash12 *= b2; hash12 %= prime2; hash22 += (pt2*tb[i])%prime2; hash22 %= prime2; pt2 = (pt2*b2)%prime2; } if(read < chunk_size) break; } printf(hash1 == hash2 && hash12 == hash22 ? "TAK\n" : "NIE\n"); } |
English