您的位置:首页 > 其它

杭电acm--2029

2015-09-15 22:40 260 查看
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。

[align=left]Input[/align]
输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。

[align=left]Output[/align]
如果一个字符串是回文串,则输出"yes",否则输出"no".

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<math.h>
//#define SIZE 100

void main()
{
int n,i,t;
char c, arr[100];
scanf("%d\n", &n);
while (n-- > 0)
{
int count = 0;
for (i = 0; (c = getchar()) != '\n'; i++)
{
arr[i] = c;
t = i;
}
for (int i = 0, j = t; i<t / 2; i++, j--)
if (arr[i] == arr[j])
{
count++;
}
if(count==t/2)
printf("yes");
else
printf("no");
printf("\n");
}

system("pause");
}



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: