#include <cstdio> const long long MOD1=1000000009, MOD2=1000696969, p1=29, p2=31; int main(){ int n; scanf("%d\n", &n); char c; c=getchar(); long long pocz1=0, pocz2=0, kon1=0, kon2=0, mnoznik1=1, mnoznik2=1; while(c>='a' && c<='z'){ pocz1= (pocz1 + (c-'a'+1)*mnoznik1)%MOD1; pocz2= (pocz2 + (c-'a'+1)*mnoznik2)%MOD2; mnoznik1=(mnoznik1*p1)%MOD1; mnoznik2=(mnoznik2*p2)%MOD2; kon1=(kon1*p1+ (c-'a'+1))%MOD1; kon2=(kon2*p2+ (c-'a'+1))%MOD2; c=getchar(); } if (pocz1 == kon1 && pocz2 == kon2){ 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 | #include <cstdio> const long long MOD1=1000000009, MOD2=1000696969, p1=29, p2=31; int main(){ int n; scanf("%d\n", &n); char c; c=getchar(); long long pocz1=0, pocz2=0, kon1=0, kon2=0, mnoznik1=1, mnoznik2=1; while(c>='a' && c<='z'){ pocz1= (pocz1 + (c-'a'+1)*mnoznik1)%MOD1; pocz2= (pocz2 + (c-'a'+1)*mnoznik2)%MOD2; mnoznik1=(mnoznik1*p1)%MOD1; mnoznik2=(mnoznik2*p2)%MOD2; kon1=(kon1*p1+ (c-'a'+1))%MOD1; kon2=(kon2*p2+ (c-'a'+1))%MOD2; c=getchar(); } if (pocz1 == kon1 && pocz2 == kon2){ printf("TAK\n"); } else { printf("NIE\n"); } return 0; } |