解题思路:
注意事项:
参考代码:
#include "stdio.h"
#include "stdlib.h"
#define MaxSize 100
typedef int ElemType;
typedef struct
{
ElemType data[MaxSize];
int top;
}SqStack;
void init(SqStack& S)
{
S.top = -1;
}
bool push(SqStack& S, ElemType e)
{
if (S.top == MaxSize - 1)
{
return false;
}
S.top++; S.data[S.top] = e;
return true;
}
bool pop(SqStack& S, ElemType& x)
{
if (S.top == -1) { return false; }
x = S.data[S.top];
S.top--;
return true;
}
void print(SqStack S)
{
for (int i = 0; i <= S.top; i++)
{
printf("%d ", S.data[i]);
}
}
int main()
{
int n;
while (scanf("%d", &n)!=EOF)
{
if (n == 0) { break; }
SqStack S;
init(S);
ElemType X;
char A[2];
for (int i = 0; i < n; i++)
{
scanf("%s", A);// (A);
if (A [0]== 'P')
{
int x;//getchar();
scanf("%d", &x);
push(S, x);
}
if (A[0] == 'O')
{
if (S.top == -1) { continue; }
int E;
pop(S,E);
}
if (A [0]== 'A')
{
if (S.top == -1) { printf("E\n"); continue; }
printf("%d\n", S.data[S.top]);
}
}
printf("\n");
}
}
0.0分
0 人评分
ASCII帮了大忙浏览:748 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:994 |
求组合数 (C语言代码)浏览:1153 |
C语言程序设计教程(第三版)课后习题9.10 (C语言代码)浏览:550 |
Cylinder (C语言描述+详细分析)浏览:3263 |
2^k进制数 (C语言描述,蓝桥杯)浏览:1420 |
GC的苦恼 (C语言代码)浏览:618 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:463 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:607 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:809 |