又见回文

又见回文

Time Limit: 1000 ms  Memory Limit: 65536 KiB

Problem Description

    “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。现在呢,就是让你判断输入的字符串是否是回文串。

Input

    有多组输入,每行输入一串字符,保证字符串长度不会大于 100000,字符串由大小写英文字母和空格组成,以字符串“2013”作为结束标志。

Output

    每行输出一个字符串,如果输入是回文串,输出“YES”,否则输出“NO”(注意:判断的时候空格是不作判断的,详见样例)。

Sample Input

aaaa
ggg g
lozxvxoMJBCHsTXooXTsHCBJMoxvxzol
i am a good acmer
2013

Sample Output

YES
YES
YES
NO

Hint

 

Source

fenggang


AC代码

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char str[105000],str1[105000];
int main()
{
char nape[5]="2013";
while(gets(str))
{
if(strcmp(nape,str)==0)
break;
int length=strlen(str),n=0,t=0;
int j=length-1;
for(int i=0;;)
{
while(str[i]==' ')
i++,t++;
while(str[j]==' ')
j--,t++;
if(i>=length||j<0)
break;
if(str[i]==str[j]&&str[i]!=' '&&str[j]!=' ')
n++,i++,j--;
else
i++,j--;
}
if(n==length-t/2)
printf("YES\n");
else
printf("NO\n");
}
}

猜你喜欢

转载自blog.csdn.net/YT201758501112/article/details/80777490