codeup— 5901: 【字符串】回文串

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

题目链接:http://www.codeup.cn/problem.php?id=5901

题目描述

读入一串字符,判断是否是回文串。“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。

输入

一行字符串,长度不超过255。

输出

如果是回文串,输出“YES”,否则输出“NO”。

样例输入

12321

样例输出

YES
#include<iostream>
#include<cstring>
using namespace std;
bool jud(char str[]) {
	int len=strlen(str);
	for(int i=0;i<len/2;i++){
		if(str[i]!=str[len-1-i]){
			return false;
		}
	}
	return true;
}
int main(){
	char str[256];
	while(gets(str)){
		if(jud(str)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/83038376