Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
输入一串字符(长度小于100),判断该串字符是否是回文串(正序读与逆序读内容相同)。
Input
输入一串字符(长度小于100)。
Output
若该串字符是回文串输出“yes",否则输出”no“。
Sample Input
asdfgfdsa
Sample Output
yes
Hint
Source
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char a[101];
int n,i;
gets(a);
n = strlen(a);
for(i=0;i<n/2;i++)
{
if(a[i]!=a[n-i-1]) //前后对应相等,若不相等结束循环;
break;
}
if(i<n/2) printf("no\n");
else printf("yes\n");
return 0;
}
运行结果:
asdfgfdsa
yes
Process returned 0 (0x0) execution time : 4.503 s
Press any key to continue.