33判断字符串是否为回文

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

总时间限制: 
1000ms
 
内存限制: 
65536kB
描述

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

输入
输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。
输出
如果字符串是回文,输出yes;否则,输出no。
样例输入
abcdedcba
样例输出
yes


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char a[10001];
char b[10001];
int now;
int find1;
int main()
{
    gets(a);
    int l=strlen(a);
    if(l%2==1)//如果长度是奇数
    {
         find1=l/2+1;//从中间向两边寻找
        int i=0;
        while(i!=find1)
        {
        if(a[find1-i-1]!=a[find1+i-1])//如果两边的值不相同
        {
            cout<<"no";
            return 0;
        }
        else i++;
    }
    cout<<"yes";
    }
    else 
    {
         find1=l/2;
         int i=0;
        while(i!=find1)
        {
        if(a[find1-i-1]!=a[find1+i])
        {
            cout<<"no";
            return 0;
        }
        else i++;
        }
            cout<<"yes";
    }
    return 0;
}

 

posted @ 2017-03-01 09:00  自为风月马前卒  阅读(643)  评论(0编辑  收藏  举报

Contact with me