计算机考研复试真题 回文字符串

题目描述

给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。

输入描述:

输入包括一行字符串,其长度不超过1000。

输出描述:

可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。
示例1

输入

hellolleh
helloworld

输出

Yes!
No!




/**/
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    while(cin>>str){
        for(int i=0,j=str.size()-1 ; i<j ; ++i,--j){
            if(str[i]!=str[j]){
                cout<<"No!"<<endl;
                return 0;  
            }                 
        }
        cout<<"Yes!"<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/parzulpan/p/9923178.html