Problem C: 判断字符串是否为回文
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2460 Solved: 1515
[ Submit][ Status][ Web Board]
Description
编写程序,判断输入的一个字符串是否为回文。若是则输出“Yes”,否则输出“No”。所谓回文是指順读和倒读都是一样的字符串。
Input
Output
Sample Input
abcddcba
Sample Output
Yes
HINT
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char a[50];
string b;
int i,len;
bool f=true;
//cin>>b;
//char *p;
//p=b;
gets(a);//输入一个未知长度的数组
len=strlen(a);//获取未知长度数组的长度
for(i=0;i<=len-1;i++)
{
if(a[i]!=a[len-1-i])
{
cout<<"NO"<<endl;
break;
f=false;
}
}
if(f==true)
{
cout<<"YES"<<endl;
}
//len=strlen(b);
/*
while(scanf("%c",&t)!=EOF)
{
a[i]=t;
i++;
}*/
cout <<a<< endl;
return 0;
}