AC日记——判断字符串是否为回文 openjudge 1.7 33

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

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

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

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

思路:

  模拟;

 

来,上代码:

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;

int len;

string word;

bool check()
{
    int l=0,r=len-1;
    while(r>l)
    {
        if(word[l]!=word[r]) return false;
        l++,r--;
    }
    return true;
}

int main()
{
    cin>>word;
    len=word.length();
    if(check()) printf("yes\n");
    else printf("no\n");
    return 0;
} 

 

转载于:https://www.cnblogs.com/IUUUUUUUskyyy/p/6119622.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值