Description
输入一串字符(长度小于100),判断该串字符是否是回文串(正序读与逆序读内容相同)。
Input
输入一串字符(长度小于100)。
Output
若该串字符是回文串输出“yes",否则输出”no“。
Sample
Input
asdfgfdsa
Output
yes
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
//1.定义一个长度为101的字符数组,定义字符长度n,定义标志变量f
//2.for循环遍历将i与n-1-i经行比较,发现不等的将f=0;
//3.发现不相等的即刻跳出循环将f=0
char str[101];
int n;
int main()
{
int f=1;
cin.getline(str,102);
n=strlen(str);
for (int i=0; i<=(n-1)/2; i++)
{
if(str[i]!=str[n-i-1])
{
f=0;
}
}
if(f==0)
{
printf("no\n");
}
else
{
printf("yes\n");
}
return 0;
}