解题思路:
注意事项:
参考代码:
#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 人评分
用筛法求之N内的素数。 (C语言代码)浏览:1234 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:470 |
WU-整除问题 (C++代码)浏览:612 |
Cylinder (C语言描述+详细分析)浏览:3263 |
分糖果 (C语言代码)浏览:912 |
1134题解(求分析)浏览:724 |
多输入输出练习2 (C语言代码)浏览:1655 |
简单的a+b (C语言代码)浏览:635 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:604 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:682 |