我是靠谱客的博主 文静手链,最近开发中收集的这篇文章主要介绍判断字符串是否为回文(C/C++),觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

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

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

Sample Input
abcdedcba
Sample Output
yes

直接再存一个倒序的串,判断和之前的一不一样即可;

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include <algorithm>
#include<string.h>
#include<queue> 
#include<math.h>
#include<set>
#define llu unsigned long long
using namespace std;


int main()
{
	string s1;
	cin >> s1;
	int n=s1.size();
	char s2[n+10];
	int j=0;
	for(int i=n-1;i>=0;i--)  
	{
		s2[j++]=s1[i];
	}
		
	if(s1==s2)cout << "yes" << endl ;
	else cout << "no" << endl ;
	
	
	return 0;
}




最后

以上就是文静手链为你收集整理的判断字符串是否为回文(C/C++)的全部内容,希望文章能够帮你解决判断字符串是否为回文(C/C++)所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部