判斷迴文串
Time Limit: 2000 MS Memory Limit: 4096 KBTotal Submit: 298 Accepted: 50 Page View: 525
Submit Status Discuss
Description
某天吃飯的時候,FM有了一個帥氣idea,其實是個傻逼題?題意很簡單,給一個字符串判斷是否是迴文串?
PS:如果一個字符串正着讀和反着讀都一樣,那麼這個字符串爲迴文串,比如aba,cc,cddc爲迴文串,而ac,acda,adA則不是迴文串。
Input
第二行爲這個字符串,該串僅包含大小寫字母。
Output
aaaaaaaa
7
tangcan
3
lyl
NO
YES
Hint
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<stdlib.h>
#include<time.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#define ll long long
#define ull unsigned long long
#define qq printf("QAQ\n");
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const ull hmod1=1e9+97;
const ull hmod2=1e9+93;
const ull base1=133;
const ull base2=131;
const double e=exp(1.0);
const double pi=acos(-1);
int main()
{
int n;
ll a,b,c,d,b1,b2;
while(scanf("%d",&n)!=EOF)
{
char cc;
a=0,b=0;
getchar();
for(int i=1;i<=n/2;i++)
{
cc=getchar();
a=(a*base1+(ull)cc)%hmod1;
b=(b*base2+(ull)cc)%hmod2;
}
if(n&1)getchar();
b1=1,b2=1,c=0,d=0;
for(int i=1;i<=n/2;i++)
{
cc=getchar();
c=(c+(ull)cc*b1)%hmod1;
d=(d+(ull)cc*b2)%hmod2;
b1=(b1*base1)%hmod1;
b2=(b2*base2)%hmod2;
}
//if(a==c)printf("YES\n");
if(a==c&&b==d)printf("YES\n");
else printf("NO\n");
}
return 0;
}