1192.回文字符串

题目描述:

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

输入:

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

输出:

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

样例输入:
hellolleh
helloworld
样例输出:
Yes!
No!

#include<iostream>
#include<string.h>
using namespace std;

int main(){
    char a[1000];
    while(gets(a))
    {
        int len=strlen(a);
        int i,j,flag=1;
        for(i=0,j=len-1;i<=j;i++,j--)
        {
            if(a[i]!=a[j])
            {
                flag=0;
            }
        }
        if(flag)
        cout<<"Yes!"<<endl;
        else cout<<"No!"<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/bernieloveslife/p/9735240.html