1146:判断字符串是否为回文

【题目描述】

输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。

【输入】

输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。

【输出】

如果字符串是回文,输出yes;否则,输出no。

【输入样例】

abcdedcba

【输出样例】

yes

是一种判断回文的方法

#include<bits/stdc++.h>
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int flag=0;
    for(int i=0,j=s.size()-1;i<j;i++,j--)
    {
        if(s[i]==s[j])
            continue;
        else
            flag=1;
    }
    if(flag)
        cout<<"no"<<endl;
    else
        cout<<"yes"<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wchenchen0/article/details/81041196