Information
- ID
- 330
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 2
- Tags
- # Submissions
- 153
- Accepted
- 49
- Uploaded By
#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
int main()
{
int t,n,b;
cin>>t;
while(t--)
{
cin>>n;
stack<int>a;
while(n--)
{
char s[20];
cin>>s;
if(!strcmp(s,"pop"))//将字符串匹配,符合就进行下列操作
{
if(a.empty()) cout<<"Empty"<<endl;//先判断它是否为空,空就按题目要求输出
else
{
cout<<a.top()<<endl;//否则就输出出栈元素
a.pop();//同时删除
}
}
else if(!strcmp(s,"push"))//匹配就直接入栈
{
cin>>b;
a.push(b);
}
}
}
return 0;
}
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.