#include <bits/stdc++.h>
using namespace std;
#define VAR(n,v) decltype(v) n=(v)
#define REP(i,n) for(int i=1; i<=(n); ++i)
#define FOR(i,a,b) for(VAR(i,a); i!=(b); ++i)
#define FORE(it,t) FOR(it,t.begin(),t.end())
typedef vector<int> vi;
#define pb push_back
typedef pair<int,int> pii;
#define mp make_pair
#define st first
#define nd second
typedef unsigned long long ll;
#define INF 1000000001
#define sz size()
#define ALL(t) (t).begin(),(t).end()
#define SC(a) scanf("%d\n", &a)
#define GET(a) int a; SC(a)
#define ISDEBUG 0
#define dprintf(...) if(ISDEBUG) \
{printf("\033[31m"); printf(__VA_ARGS__); printf("\033[0m");}
template <class It> void dptab(It b, It e, const char* f="%d ")
{if(ISDEBUG) {for(It it=b; it!=e; ++it) dprintf(f, *it); dprintf("\n"); }}
ll x = 71;
ll fast_pow(int exp) {
if(0 == exp)
return 1;
ll half = fast_pow(exp/2);
return exp%2 ? half * half * x : half * half;
}
int main() {
scanf("%*d\n");
char c;
ll hash = 0;
ll rev_hash = 0;
ll power = 1;
while(EOF != scanf("%c", &c)) {
if(c < 'a' || c > 'z')
continue;
c -= 'a';
hash = hash * x + c;
rev_hash += c * power;
power *= x;
}
dprintf("hash = %lld\n", hash);
dprintf("rev_hash = %lld\n", rev_hash);
printf("%s\n", hash == rev_hash ? "TAK" : "NIE");
}
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 | #include <bits/stdc++.h> using namespace std; #define VAR(n,v) decltype(v) n=(v) #define REP(i,n) for(int i=1; i<=(n); ++i) #define FOR(i,a,b) for(VAR(i,a); i!=(b); ++i) #define FORE(it,t) FOR(it,t.begin(),t.end()) typedef vector<int> vi; #define pb push_back typedef pair<int,int> pii; #define mp make_pair #define st first #define nd second typedef unsigned long long ll; #define INF 1000000001 #define sz size() #define ALL(t) (t).begin(),(t).end() #define SC(a) scanf("%d\n", &a) #define GET(a) int a; SC(a) #define ISDEBUG 0 #define dprintf(...) if(ISDEBUG) \ {printf("\033[31m"); printf(__VA_ARGS__); printf("\033[0m");} template <class It> void dptab(It b, It e, const char* f="%d ") {if(ISDEBUG) {for(It it=b; it!=e; ++it) dprintf(f, *it); dprintf("\n"); }} ll x = 71; ll fast_pow(int exp) { if(0 == exp) return 1; ll half = fast_pow(exp/2); return exp%2 ? half * half * x : half * half; } int main() { scanf("%*d\n"); char c; ll hash = 0; ll rev_hash = 0; ll power = 1; while(EOF != scanf("%c", &c)) { if(c < 'a' || c > 'z') continue; c -= 'a'; hash = hash * x + c; rev_hash += c * power; power *= x; } dprintf("hash = %lld\n", hash); dprintf("rev_hash = %lld\n", rev_hash); printf("%s\n", hash == rev_hash ? "TAK" : "NIE"); } |
English