FZU 2091 播放器(栈应用)

时间:2023-03-09 04:00:11
FZU 2091 播放器(栈应用)

栈基础应用

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
stack<int>s;
while(!s.empty()) s.pop();
s.push();
char op[];
int num;
while(m--)
{
scanf("%s",op);
if(!strcmp(op,"PRE"))
{
if(s.size() == )
{
printf("%d\n",s.top());
}
else
{
s.pop();
printf("%d\n",s.top());
}
}
else if(!strcmp(op,"NEXT"))
{
int now = s.top() + ;
if(now > n) now = n;
printf("%d\n",now);
if(s.empty())
{
s.push(now);
}
else if(s.top() != now)
{
s.push(now);
}
}
else
{
int now;
scanf("%d",&now);
printf("%d\n",now);
if(s.empty())
{
s.push(now);
}
else if(s.top() != now)
{
s.push(now);
}
}
}
}
}

相关文章