- ·上一篇资讯:今年二年级转学到厦门读书
- ·下一篇资讯:信息学C++ 字符串逆序
信息学C++:判断字符串是否为回文
题目描述
输入一个字符串,输出该字符串是否回文。回文是指顺读和倒读都一样的字符串。
输入格式
输入为一行字符串(字符串中没有空白字符,字符串长度不超过100)
输出格式
如果字符串是回文,输出yes;否则,输出no。
样例
样例输入
abcdedcba
样例输出
yes
========
#include<bits/stdc++.h>
#include<iostream>
#include<cctype>
using namespace std;
int main(){
string s;
cin>>s;
int flag=0;
for(int i=0,j=s.size()-1;i<j;i++,j--){
if(s[i]==s[j])
continue;
else
flag=1;
}
if(flag)
cout<<"no"<<endl;
else
cout<<"yes"<<endl;
return 0;
}
===
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
bool flag=true;
char str[100];
gets(str);
int len;
len=strlen(str);
for(int i=0; i<len; i++) {
if(str[i]!=str[len-1-i]) {//如果第i项等于倒数第i项
flag=false;
}
}
if(flag) {
cout << "yes";
} else {
cout << "no";
}
return 0;
}
关键词:
作者:惠民大叔(非官方微信免费提供积分入学问题咨询。)
惠民大叔家长社群开放报名:
1、一整年的升学政策同步更新,
2、一整年的插班生信息更新,
3、一整年升学政策的独家解读,
4、一整年几千条的家长咨询回复,
5、一整年无限次的升学咨询,
6、以及不公开的信息分享等等。
继续指导大家的做好升学规划,带领大家探索孩子上学的更多可能性,我们相信,这将是你最值得加入的一个社群!
了解更多关于上学报名的事,扫一扫二维码: