C++高手进!~十万火急!

来源:百度知道 编辑:UC知道 时间:2024/06/19 12:58:53
回文就是正读反读都一样的字符串。例如“radar”反读的结果也是“radar”。请编写一个程序,从键盘输入一个字符串,判断这个字符串是否是回文:如果是,打印YES;如果不是,打印NO 。

给你写伪码 自己编译 找错的过程中你会学到很多东西

input inStr
int i = 0
boolean check = true

if (inStr.length%2==0)
check = false
while (check AND i < inStr.length)
if (NOT(inStr[i]=inStr[inStr.length-i-1]))
check = false
end
if check
output "YES"
else
output "NO"

输入行字符串,判断是否为回文
如果是,打印YES;如果不是,打印NO;
程序如下:

#include"stdio.h"
#include"string.h"
#define n 50
void main()
{
int i;
char st1[n+1];
char *pst1,*pst2;
printf("please input a string:");
scanf("%s",st1);
pst1=st1;
pst2=st1;
while(*pst1!='\0')
pst1++;
i=0;
pst1--;
while(*pst1==*pst2 )
{

pst1--;
pst2++;
i++;
}
if(i==strlen(st1))
printf("yes\n&q