题目如图所示
代码如下
方法一
#include<stdio.h>
int main()
{
char a[99];
char b=0;
int c=0,d=0,i,k=1;
b=getchar();
while(b!='@')
{
a[c]=b;
c++;
b=getchar();
}
while(a[d]!='&')
d++;
for(i=d-1;i>=0;i--)
{
if(a[i]!=a[2*d-i])
k=0;
}
if(k==1)
printf("是回文序列");
else
printf("不是回文序列");
}
运行截图
方法二
#include<stdio.h>
void main()
{
typedef struct
{
char elem[99];
int top;
}huiwen;
char b;
int c = 1;
huiwen s;
s.top = -1;
b = getchar();
while (b != '&')
{
s.top++;
s.elem[s.top] = b;
b = getchar();
}
b = getchar();
while (b != '@')
{
if (b != s.elem[s.top])
{
c = 0; break;
}
else
{
s.top--;
b = getchar();
}
}
if (c)
printf("是回文序列");
else
printf("不是回文序列");
}
运行截图