题解 | 堆栈的使用(14行够了)
堆栈的使用
https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26
#include <stdio.h>
int main() {
int stk[1000], top, n;
while (top=-1, scanf("%d", &n) != EOF) {
char c;
for(int i=0; i<n&&scanf(" %c", &c); ++i){
if(c=='A' && top==-1) printf("E\n");
else if(c=='A') printf("%d\n", stk[top]);
else if(c=='P') scanf("%d", &stk[++top]);
else if(top>-1) --top;
}
}
}
查看14道真题和解析