首页 > 其他分享 >c语言栈-回文

c语言栈-回文

时间:2024-10-13 20:48:41浏览次数:1  
标签:语言 int top ++ MAXSIZE printf world 回文

include<stdio.h>

include<stdlib.h>

define MAXSIZE 7

//定义结构体
struct Stack {
char world[MAXSIZE];
int top;
};

//定义栈
struct temp {
struct Stack s;
};

int main() {
Stack s{};
//入栈
char c1[MAXSIZE] = { 0 };
printf("输入字符串,最多%d个字符\n",MAXSIZE);
for (int i = 0; i < MAXSIZE; i++) {
char c = '0';
scanf_s("%c", &c, sizeof(c));
s.world[++(s.top)] = c;
c1[i] = c;
}
//出栈
printf("字符串输出顺序:\n");
int t = 0;
for (int i = 0; i < MAXSIZE; i++) {
if (s.top>=0) {
printf("%c", s.world[(s.top)]);
printf("\n");
if (s.world[(s.top)] == c1[MAXSIZE-1-i]) {
t++;
}
s.top--;
}
}
if (t == MAXSIZE) {
printf("该串字符是回文!");
}
else {
printf("该串字符不是回文!");
}
return 0;
}

标签:语言,int,top,++,MAXSIZE,printf,world,回文
From: https://www.cnblogs.com/LiuHuWei/p/18462944

相关文章