【题目描述】
输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。
【输入】
输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。
【输出】
如果字符串是回文,输出yes;否则,输出no。
【输入样例】
abcdedcba
【输出样例】
yes
【源程序】
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
char s[100];
int len,position;
int i,j;
gets(s);//获取字符串s
len=strlen(s);//求字符串长度
i=0;
j=len-1;//记录字符串首、尾位置
while( (i<j) &&(s[i]==s[j]) )//从首尾同时向中间判定,若不是回文串,则退出循环
{
i++;
j--;
}
if(i>=j)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
return 0;
}

1354

被折叠的 条评论
为什么被折叠?



