又见回文
TimeLimit: 1000MS Memory Limit: 65536KB
Problem Description
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。现在呢,就是让你判断输入的字符串是否是回文串。
Input
有多组输入,每行输入一串字符,保证字符串长度不会大于 100000,字符串由大小写英文字母和空格组成,以字符串“2013”作为结束标志。
Output
每行输出一个字符串,如果输入是回文串,输出“YES”,否则输出“NO”(注意:判断的时候空格是不作判断的,详见样例)。
Example Input
aaaa
ggg g
lozxvxoMJBCHsTXooXTsHCBJMoxvxzol
i am agood acmer
2013
Example Output
YES
YES
YES
NO
Hint
Author
fenggang
#include <iostream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stdio.h>
using namespace std;
int main()
{
char s[100003];
while(gets(s))
{
if(strcmp(s,"2013")==0)
{
return 0;
}
int l = strlen(s);
char *p,*q;
p = s;
q = s+l-1;
int f =1;
while(p<=q)
{
if(*p==' ')
{
p++;
continue;
}
else if(*q==' ')
{
q--;
continue;
}
if(*p==*q)
{
p++;
q--;
}
else
{
f = 0;
break;
}
}
if(f) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 0ms
Take Memory: 252KB
Submit time: 2017-01-16 20:42:25
****************************************************/