2013年中南大学复试-回文串问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Datura0822/article/details/88738441

2013年中南大学复试机试题解

回文串问题

题目来源: http://pipioj.online/problem.php?id=1000.
题目描述
“回文串”是一个正读和反读都一样的字符串,字符串由数字和小写字母组成,比如“level”或者“abcdcba”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。
输入
输入包含多个测试实例,每一行对应一个字符串,串长最多100字母。
输出
对每个字符串,输出它是第几个,如第一个输出为"case1:";如果一个字符串是回文串,则输出"yes",否则输出"no",在yes/no之前用一个空格。
样例输入
level
abcde
noon
haha
样例输出
case1: yes
case2: no
case3: yes
case4: no

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;

int main()
{
    int t=0;
    string s;
    while(cin>>s){
        t++;
        int flag=1;
        for(int i=0;i<s.length()/2;i++)
        {
            if(s[i]!=s[s.length()-1-i]) {flag=0;break;}
        }
        if(flag) printf("case%d: yes\n",t);
        else printf("case%d: no\n",t);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Datura0822/article/details/88738441
今日推荐