Problem Link:点击打开链接
题目描述
给出一个长度不超过1000的字符串,判断它是不是回文(顺读,逆读均相同)的。
输入描述:
输入包括一行字符串,其长度不超过1000。
输出描述:
可能有多组测试数据,对于每组数据,如果是回文字符串则输出"Yes!”,否则输出"No!"。
输入例子:
hellolleh helloworld
输出例子:
Yes! No!
AC code:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<math.h>
#include<string.h>
#include<queue>
#include<vector>
#include<set>
#define LL long long
#define exp 1e-9
#define MAXN 1000010
using namespace std;
int main()
{
// freopen("D:\\in.txt","r",stdin);
int i,j,l1;
char s1[1111]="";
while(gets(s1))
{
l1=strlen(s1);
for(i=0,j=l1-1;i<j;++i,--j)
{
if(s1[i]!=s1[j])
break;
}
if(i>=j)
printf("Yes!\n");
else
printf("No!\n");
}
return 0;
}
判断回文字符串的C++实现

本文介绍了一个简单的C++程序,用于判断输入的字符串是否为回文字符串。通过比较字符串首尾字符的方式,实现了对回文特性的快速检测。
400

被折叠的 条评论
为什么被折叠?



