#include <iostream>
#include <stack>
#include <cstring>
#include <cstdlib>
using namespace std;
stack<int> s1;
stack<int> s2;
int main()
{
int n,length,push;
string p;
cin>>n;
while(n--)
{
cin >> p;
if(p == "PUSH")
{
cin>>push;
s1.push(push);
}
else
{
if(s2.empty())
{
if(s1.empty())
{
cout<<-1<<endl;
}
else
{
length = s1.size();
while(length--)
{
s2.push(s1.top());
s1.pop();
}
cout<<s2.top()<<endl;
s2.pop();
}
}
else
{
cout<<s2.top()<<endl;
s2.pop();
}
}
}
return 0;
}
/**************************************************************
Problem: 1512
User: 萧然677
Language: C++
Result: Accepted
Time:530 ms
Memory:1652 kb
****************************************************************/
题目1512:用两个栈实现队列
最新推荐文章于 2016-08-23 10:42:07 发布