#include <cstdio> #define MOD 32538703 //my favorite prime number #define HASHNUMB 47 //my second favorite prime int main(){ int _unused; scanf("%d ",&_unused); unsigned int hash1=0,hash2=0; unsigned int hashnumbpower=1; char chr=0; while(1){ if(scanf("%c",&chr)!=1) break; if(chr>'z'||chr<'a') break; chr-='a'-1; hashnumbpower=(hashnumbpower*HASHNUMB)%MOD; hash1=(hash1+chr*hashnumbpower)%MOD; hash2=((hash2+chr)*HASHNUMB)%MOD; //if(hash1==hash2) // printf("t"); //else // printf("n"); } if(hash1==hash2) printf("TAK\n"); else printf("NIE\n"); 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 | #include <cstdio> #define MOD 32538703 //my favorite prime number #define HASHNUMB 47 //my second favorite prime int main(){ int _unused; scanf("%d ",&_unused); unsigned int hash1=0,hash2=0; unsigned int hashnumbpower=1; char chr=0; while(1){ if(scanf("%c",&chr)!=1) break; if(chr>'z'||chr<'a') break; chr-='a'-1; hashnumbpower=(hashnumbpower*HASHNUMB)%MOD; hash1=(hash1+chr*hashnumbpower)%MOD; hash2=((hash2+chr)*HASHNUMB)%MOD; //if(hash1==hash2) // printf("t"); //else // printf("n"); } if(hash1==hash2) printf("TAK\n"); else printf("NIE\n"); return 0; } |