回文字符串问题

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值