求教:回文挑错,输出没错,过样例没错,超时了。
题目:与以往的回文不同,只判断字母是不是构成回文,不是字母的一律当作不存在。Sample Input
radar
rAd. Ar
radiar
able was I ere I saw elba!
b
bb
ab
aabaa
aabbaa
aab2aa
aabaaa
This is a palindrome
radar is a palindrome
a man, a plan, a canal, panama!
a bell was eye, ear I saw elbow
go hang a salami, bub, i’m a lasagna hog!!
Sample Output
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
NO
YES
代码,用指针实现
#include "stdio.h"
#include "string.h"
int main()
{
int i;
char a[101];
char *p,*q;
while(gets(a)!=EOF)
{ i=strlen(a);
p=&a[0];
q=&a[i-1];
while(p<q)
{
if(*p==*q)
{
p++;
q--;
}
else if(!((*p<='A'&&*p>='Z')||(*p>='a'&&*p<='z') ) ) *p++;
else if(!((*q>='A'&&*q<='Z')||(*q>='a'&&*q<='z') ) ) *q--;
else {
printf("N0\n");
break;
}
}
if(p>=q) printf("YES\n");
} return 0;
}