#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main()
{
stack<int> st,st_min;
int n,x;
char s[2];
while(scanf("%d",&n)!=EOF)
{
for(int i=0; i<n; i++)
{
scanf("%s",&s);
if(s[0]=='s')
{
scanf("%d",&x);
st.push(x);
if(!st_min.empty())
{
int t=st_min.top();
if(x<t)
{
st_min.push(x);
}
}
else
{
st_min.push(x);
}
printf("%d\n",st_min.top());
}
else
{
if(!st.empty())
{
int t=st.top();
st.pop();
if(t==st_min.top())
{
st_min.pop();
}
}
if(!st_min.empty())
{
printf("%d\n",st_min.top());
}
else
{
printf("NULL\n");
}
}
}
}
return 0;
}
/**************************************************************
Problem: 1522
User: jasonhaven
Language: C++
Result: Accepted
Time:20 ms
Memory:1524 kb
****************************************************************/
题目1522:包含min函数的栈
最新推荐文章于 2019-11-26 13:56:24 发布