题目描述
Lucy give you a string s(s1s2s3...sn) .
If(s1s2s3...sn)=(snsn-1sn-2...s1) ,you tell Lucy YES,otherwise ,you tell Lucy NO.
For example.
Lucy give you “abba”,you should tell her “YES”
Lucy give you “abbc”,you should tell her “NO”
Lucy give you “abxba”,you should tell her “YES”
If(s1s2s3...sn)=(snsn-1sn-2...s1) ,you tell Lucy YES,otherwise ,you tell Lucy NO.
For example.
Lucy give you “abba”,you should tell her “YES”
Lucy give you “abbc”,you should tell her “NO”
Lucy give you “abxba”,you should tell her “YES”
输入
The first line of the input gives the number of test cases T(1<T<1000). T test cases follow.
For each test case.
One line contains a string s('a'<=si<='z') .The length of s no more than 1000.
For each test case.
One line contains a string s('a'<=si<='z') .The length of s no more than 1000.
输出
For each test case, output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer.
样例输入
3
abb
a
abbc
abxba
样例输出
Case #1: YES
Case #2: NO
Case #3: YES
分析:判断是否是回文字符串
代码如下:
#include <stdio.h>
#include <string.h>
int main (){
char str[1005];
int Case=1;
int t;
scanf ("%d",&t);
getchar();
while (t--){
scanf ("%s",str);
int x=strlen(str);
int flag=1;
for (int i=0,j=x-1;i<=j&&flag;i++,j--){
if(str[i]!=str[j]){
printf ("Case #%d: NO\n",Case++);
flag=0;
}
}
if (flag)
printf ("Case #%d: YES\n",Case++);
}
return 0;
}