题目1108:堆栈的使用

来源:互联网 发布:软件学校 编辑:程序博客网 时间:2024/06/05 21:07

#include <iostream>#include <stdio.h>#include <algorithm>#include <math.h>#include <string>#include <string.h>#include <vector>#include <queue>#include <stack>using namespace std; //1108int main(){    int n;    char c;    while(scanf("%d",&n)!=EOF&&n!=0){        //getchar();        stack<int> s;        while(!s.empty()) s.pop();        for(int i=0;i<n;i++){            cin>>c;            if(c=='P'){                int t;scanf("%d",&t);                s.push(t);            }else if(c=='A'){                if(!s.empty())                    printf("%d\n",s.top());                else                    printf("E\n");            }else if(c=='O'){                if(!s.empty()) s.pop();            }           // getchar();        }        printf("\n");    }    return 0;}/**************************************************************    Problem: 1108    User: cust123    Language: C++    Result: Accepted    Time:140 ms    Memory:1520 kb****************************************************************/


0 0
原创粉丝点击