#include <cstdio> //#include <iostream> #define REP(i,x,v)for(int i=x;i<=v;i++) #define REPD(i,x,v)for(int i=x;i>=v;i--) #define FOR(i,v)for(int i=0;i<v;i++) #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define pb push_back #define sz size() #define mp make_pair #define fi first #define se second #define ll long long #define IN(x,y) ((y).find((x))!=(y).end()) #define LOLDBG #ifdef LOLDBG #define DBG(vari) cout<<#vari<<" = "<<vari<<endl; #define DBG2(v1,v2) cout<<(v1)<<" - "<<(v2)<<endl; #else #define DBG(vari) #define DBG2(v1,v2) #endif #define CZ(x) scanf("%d",&(x)); #define CZ2(x,y) scanf("%d%d",&(x),&(y)); #define ALL(x) (x).begin(),(x).end() using namespace std; //typedef pair<int,int> pii; //typedef vector<int> vi; //mt19937 rng(time(0)); #define tries 2 int r[]={22,14245,5}; int rpow[tries]; //int rinv[tries]; int p[]={1000001011,1000001021,1000003013}; int accf[tries]; int accb[tries]; int main() { int n;scanf("%d",&n); char c; int a; int len=0; FOR(i,tries) rpow[i]=1; FOR(i,tries) accf[i]=accb[i]=0; ll x; while((c = getchar()) !=EOF) { if (!('a'<=c && c<='z')) continue; FOR(i,tries) { x=accf[i]+c*1LL*rpow[i]; accf[i]=x%p[i]; rpow[i]=(rpow[i]*1LL*r[i])%p[i]; } FOR(i,tries) { accb[i]=(accb[i]*1LL*r[i]+c)%p[i]; } } bool match=1; FOR(i,tries) if (accf[i]!=accb[i]) match=0; if (match) printf("TAK\n"); else printf("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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #include <cstdio> //#include <iostream> #define REP(i,x,v)for(int i=x;i<=v;i++) #define REPD(i,x,v)for(int i=x;i>=v;i--) #define FOR(i,v)for(int i=0;i<v;i++) #define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) #define pb push_back #define sz size() #define mp make_pair #define fi first #define se second #define ll long long #define IN(x,y) ((y).find((x))!=(y).end()) #define LOLDBG #ifdef LOLDBG #define DBG(vari) cout<<#vari<<" = "<<vari<<endl; #define DBG2(v1,v2) cout<<(v1)<<" - "<<(v2)<<endl; #else #define DBG(vari) #define DBG2(v1,v2) #endif #define CZ(x) scanf("%d",&(x)); #define CZ2(x,y) scanf("%d%d",&(x),&(y)); #define ALL(x) (x).begin(),(x).end() using namespace std; //typedef pair<int,int> pii; //typedef vector<int> vi; //mt19937 rng(time(0)); #define tries 2 int r[]={22,14245,5}; int rpow[tries]; //int rinv[tries]; int p[]={1000001011,1000001021,1000003013}; int accf[tries]; int accb[tries]; int main() { int n;scanf("%d",&n); char c; int a; int len=0; FOR(i,tries) rpow[i]=1; FOR(i,tries) accf[i]=accb[i]=0; ll x; while((c = getchar()) !=EOF) { if (!('a'<=c && c<='z')) continue; FOR(i,tries) { x=accf[i]+c*1LL*rpow[i]; accf[i]=x%p[i]; rpow[i]=(rpow[i]*1LL*r[i])%p[i]; } FOR(i,tries) { accb[i]=(accb[i]*1LL*r[i]+c)%p[i]; } } bool match=1; FOR(i,tries) if (accf[i]!=accb[i]) match=0; if (match) printf("TAK\n"); else printf("NIE\n"); } |