传送门
暴力就完事了╮(╯-╰)╭
Description
“回文串”是一个正读和反读都一样的字符串,字符串由数字和小写字母组成,比如“level”或者“abcdcba”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
Input
输入包含多个测试实例,每一行对应一个字符串,串长最多100字母。
Output
对每个字符串,输出它是第几个,如第一个输出为”case1:”;如果一个字符串是回文串,则输出”yes”,否则输出”no”,在yes/no之前用一个空格。
Sample Input
level
abcde
noon
haha
Sample Output
case1: yes
case2: no
case3: yes
case4: no
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str[128],cnt = 0;
while(~scanf("%s",str))
{
printf("case%d: ",++cnt);
int len = strlen(str),flag = 1;
for(int i=0; i<len/2; i++)
if(str[i]!=str[len-i-1])
flag = 0;
if(flag)
printf("yes\n");
else
printf("no\n");
}
return 0;
}