信息学奥赛一本通(1146:判断字符串是否为回文)

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


时间限制: 1000 ms         内存限制: 65536 KB
提交数: 18324     通过数: 11354

【题目描述】

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

【输入】

输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)。

【输出】

如果字符串是回文,输出yes;否则,输出no。

【输入样例】

abcdedcba

【输出样例】

yes

【参考代码】

C代码:

#include <stdio.h>
#include <string.h>
#define N 110
char s[N];
int main()
{
    int i,j,len,flag=0;
    gets(s);
    len=strlen(s);
    for(i=0,j=len-1;i<=j;i++,j--)
    {
    	if(s[i]!=s[j])
    	{
    		flag=1;
    		break;
    	}
	}
	if(flag)
		printf("no\n");
	else
		printf("yes\n");
	return 0;
}

C++代码:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s,t;
int main()
{
    cin >> s;
    t=s;
    reverse(t.begin(),t.end());
    if(s==t)
        cout << "yes" << endl;
    else
        cout << "no" << endl;
    return 0;
}

http://ybt.ssoier.cn:8088/problem_show.php?pid=1146

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值