解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <stdlib.h>
#define len sizeof(Stack)
typedef struct s {
int data[1000];
int top;
}Stack;
void pushstack(Stack* h, int n) {
h->top++;
h->data[h->top] = n;
}
void popstack(Stack* h) {
if (h->top == -1) {
return NULL;
}
else {
h->top--;
}
}
void printstack(Stack* h) {
if (h->top == -1) {
printf("E\n"); //换行记得!!!
}
else {
printf("%d\n", h->data[h->top]);
}
}
int main() {
Stack* h;
h = (Stack*)malloc(len);
h->top = -1;
int n, t;
char s;
while (scanf("%d", &n)&&n){
for (int i = 0; i < n; i++) {
getchar();
scanf("%c", &s);
if (s == 'P') {
scanf("%d", &t);
pushstack(h, t);
}
else if (s == 'O') {
popstack(h);
}
else if (s == 'A') {
printstack(h);
}
}
h->top=-1; //每个测试样例过后,栈都清空
printf ("\n");
}
return 0;
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:593 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:458 |
C语言训练-求素数问题 (C语言代码)浏览:1451 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:602 |
母牛的故事 (C语言代码)浏览:435 |
C语言训练-排序问题<1> (C语言代码)浏览:599 |
输出正反三角形 (C语言代码)浏览:780 |
C语言程序设计教程(第三版)课后习题5.7 (Java代码)浏览:885 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:780 |
WU-复数求和 (C++代码)浏览:1995 |