判断输入的字符串是否为“回文”?

2025-03-17 13:09:45
推荐回答(2个)
回答1:

编写程序,是则输出yes,否则输出No。

#include

using namespace std;

int main()

{char s[100];

int i,j;

cout<<"请输入字符串s:"<

cin>>s;

for(i=0;s[i];i++);

for(i--,j=0;j

if(i

else cout<<"是回文串"<

return 0;

}

回答2:

#include "stdio.h"
#include "stdlib.h"
#include "string.h"

int Judger(char a[])
{
char *p=a;
char *q=a+strlen(a)-1;
while(p<=q)
{
if(*p!=*q)
return 0;
p++;
q--;
}
return 1;
}

main()
{
char str[100];
scanf("%s",str);

if(Judger(str))
{
printf("Yes!\n");
}
else
{
printf("No£¡\n");
}

system("pause");
}

测试数据:
LouZhuNiHao
No!
请按任意键继续. . .

AccepttpeccA
Yes!
请按任意键继续. . .

楼主好运!