2780: DS2025-改错题3
金币值:0
定数:1
时间限制:1.000 s
内存限制:128 M
解决:47
提交:115
正确率:40.87% 命题人:
题目描述
下列程序的功能是从键盘上输入 $n$ 个整数并依次入栈,然后从栈顶开始逆序输出这些整数。修改程序,保证运行正确。
测试代码 复制
#include <stdio.h>
#define MAXSIZE 100
typedef struct
{
int base[MAXSIZE];
int top;
} SqStack;
void init(SqStack &s)
{
s.top=s.base; /*ERROR*/
}
void push(SqStack &s, int e)
{
s.base[s.top]=e;
s.top++;
}
void pop(SqStack &s, int &e)
{
s.top--;
e=s.base[s.top];
}
int main(void)
{
int n;
scanf("%d",&n);
SqStack s;
init(s);
for(int i=1; i<=n; i++)
{
int e;
scanf("%d",&e);
push(s,e);
}
while(s.top!=0)
{
int e=pop(s); /*ERROR*/
printf("%d ",e);
}
return 0;
}
输入
第一行输入一个整数 $n$;
第二行输入 $n$ 个整数,相邻两个整数之间用空格隔开。
第二行输入 $n$ 个整数,相邻两个整数之间用空格隔开。
输出
输出 $n$ 个整数。
样例输入 复制
5
10 20 30 40 50
样例输出 复制
50 40 30 20 10