#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
const int MOD[]={991233359,991543151},B=11234141;
int main()
{
register int x[2]={0,0},y[2]={0,0},p[2]={1,1};
int n; scanf("%d",&n);
while(1)
{
char c=getchar();
if(c=='\n'||c=='\r') continue;
if(c<'a'||c>'z') break;
#define pal(j) \
x[j]=((ll)x[j]*B+c)%MOD[j],\
y[j]=(y[j]+p[j]*(ll)c)%MOD[j],\
p[j]=p[j]*(ll)B%MOD[j];
pal(0) pal(1)
}
for(int j=0;j<2;++j)
if((x[j]-y[j])%MOD[j])
{
puts("NIE");
return 0;
}
puts("TAK");
}
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 | #include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #include <time.h> #include <stdlib.h> #include <string> #include <bitset> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <sstream> #include <stack> #include <iomanip> using namespace std; #define pb push_back #define mp make_pair typedef pair<int,int> pii; typedef long long ll; typedef double ld; typedef vector<int> vi; #define fi first #define se second #define fe first #define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);} #define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);} #define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);} #define es(x,e) (int e=fst[x];e;e=nxt[e]) #define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e]) const int MOD[]={991233359,991543151},B=11234141; int main() { register int x[2]={0,0},y[2]={0,0},p[2]={1,1}; int n; scanf("%d",&n); while(1) { char c=getchar(); if(c=='\n'||c=='\r') continue; if(c<'a'||c>'z') break; #define pal(j) \ x[j]=((ll)x[j]*B+c)%MOD[j],\ y[j]=(y[j]+p[j]*(ll)c)%MOD[j],\ p[j]=p[j]*(ll)B%MOD[j]; pal(0) pal(1) } for(int j=0;j<2;++j) if((x[j]-y[j])%MOD[j]) { puts("NIE"); return 0; } puts("TAK"); } |
English