描述:
判断是否“回文”:给定 n 组字符串,对每一组字符串判断是否回文(从左往右看、从右往左看都一样,包括空格、英文、数字、符号),若是则输出 yes,否则输出 no;
Input:
4
nwpu
madam
1001
xi ix
Output:
no
yes
yes
yes
#include <stdio.h>
#include <string.h>
const int maxn = 20;
bool Judge(char str[][maxn], int x)
{
int len = strlen(str[x]);
for(int i = 0; i < len / 2; i++)
{
if(str[x][i] != str[x][len - i - 1])
{
return false;
}
}
return true;
}
int main(void)
{
int n;
scanf("%d", &n);
getchar();
char str[n][maxn];
for(int i = 0; i < n; i++)
{
gets(str[i]);
}
for(int i = 0; i < n; i++)
{
if(Judge(str, i))
{
printf("yes\n");
}
else
{
printf("no\n");
}
}
}