回文字符串问题

来源:互联网 发布:怪物猎人p3多玩数据库 编辑:程序博客网 时间:2024/06/05 23:47

A - 回文串问题
Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu
Submit

Status

Practice

CSU 1260
Description
“回文串”是一个正读和反读都一样的字符串,字符串由数字和小写字母组成,比如“level”或者“abcdcba”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。

Input
输入包含多个测试实例,每一行对应一个字符串,串长最多100字母。

Output
对每个字符串,输出它是第几个,如第一个输出为”case1:”;如果一个字符串是回文串,则输出”yes”,否则输出”no”,在yes/no之前用一个空格。

Sample Input
level
abcde
noon
haha
Sample Output
case1: yes
case2: no
case3: yes
case4: no

中文水题:回文字符串的处理

#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std ;int main(){    string str ;     int count = 0 ;     while(cin>>str){        bool flag = false ;         //cout<<str<<endl ;         int n = str.length();        for(int i = 0 ; i < n/2 ; i++){            if(str[i]==str[n-i-1]){                continue ;             }            else{                flag = true ;             }        }        if(flag == true){            cout<<"case"<<++count<<":"<<" no"<<endl;         }        else{            cout<<"case"<<++count<<":"<<" yes"<<endl;         }    }    return 0 ; }
0 0
原创粉丝点击