#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int n;
char c, olo[256];
long long hasz, hasz2, zsah, zsah2;
long long powlee[2] = {1, 1};
const long long p[2] = {29, 31};
long long mod = 1000696969;
int main()
{
fgets(olo, 255, stdin);
while( ( c = getchar_unlocked() ) != EOF )
{
if(c == '\n') continue;
n++;
hasz*=p[n%2];
hasz+=c-'a'+1;
hasz2*=p[(n+1)%2];
hasz2+=c-'a'+1;
if(hasz >= mod)hasz%=mod;
if(hasz2 >= mod)hasz2%=mod;
zsah += powlee[n%2]*(c-'a'+1);
zsah2 += powlee[(n+1)%2]*(c-'a'+1);
powlee[n%2]*=29;
powlee[(n+1)%2]*=31;
if(powlee[0] >= mod) powlee[0]%=mod;
if(powlee[1] >= mod) powlee[1]%=mod;
if(zsah >= mod)zsah%=mod;
if(zsah2 >= mod)zsah2%=mod;
}
while(hasz < 0)hasz+=mod;
while(hasz2 < 0)hasz+=mod;
while(zsah < 0)hasz+=mod;
while(zsah2 < 0)hasz+=mod;
if((n%2==1 && hasz == zsah && hasz2 == zsah2)||(n%2==0 && hasz == zsah2 && hasz2 == zsah))
{
cout << "TAK";
}
else
{
cout << "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 | #include<bits/stdc++.h> #include<stdio.h> using namespace std; int n; char c, olo[256]; long long hasz, hasz2, zsah, zsah2; long long powlee[2] = {1, 1}; const long long p[2] = {29, 31}; long long mod = 1000696969; int main() { fgets(olo, 255, stdin); while( ( c = getchar_unlocked() ) != EOF ) { if(c == '\n') continue; n++; hasz*=p[n%2]; hasz+=c-'a'+1; hasz2*=p[(n+1)%2]; hasz2+=c-'a'+1; if(hasz >= mod)hasz%=mod; if(hasz2 >= mod)hasz2%=mod; zsah += powlee[n%2]*(c-'a'+1); zsah2 += powlee[(n+1)%2]*(c-'a'+1); powlee[n%2]*=29; powlee[(n+1)%2]*=31; if(powlee[0] >= mod) powlee[0]%=mod; if(powlee[1] >= mod) powlee[1]%=mod; if(zsah >= mod)zsah%=mod; if(zsah2 >= mod)zsah2%=mod; } while(hasz < 0)hasz+=mod; while(hasz2 < 0)hasz+=mod; while(zsah < 0)hasz+=mod; while(zsah2 < 0)hasz+=mod; if((n%2==1 && hasz == zsah && hasz2 == zsah2)||(n%2==0 && hasz == zsah2 && hasz2 == zsah)) { cout << "TAK"; } else { cout << "NIE"; } } |
English