【题目描述】
输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。
【输入】
输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。
【输出】
如果字符串是回文,输出yes;否则,输出no。
【输入样例】
abcdedcba
【输出样例】
yes
代码如下
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[5000];
scanf("%s",a);
int n=strlen(a),t=0; //t限制枚举次数
int i=0,j=n-1; //i为左边,j为右边
n/=2;
while(t<n)
{
if(a[i]!=a[j]) //从外到内进行判断
break;
t++;
i++;
j--;
}
if(t==n) //输出
cout<<"yes";
else
cout<<"no";
return 0; //养成好习惯
}