一、题目
二、解题思路
三、代码
#include<iostream>
using namespace std;
#include<queue>
#include<stack>
int main()
{
int n,m,max;
queue<char> que[105];
stack<char> st;
cin>>n>>m>>max;
for(int i=1;i<=n;i++)
{
for(int j=0;j<m;j++)
{
char c;
cin>>c;
que[i].push(c);
}
}
while(1)
{
int t;
cin>>t;
if(t==-1)
{
break;
}
else if(t==0 && !st.empty())
{
cout<<st.top();
st.pop();
}
else if(t>0 && !que[t].empty())
{
if(st.size()==max)
{
cout<<st.top();
st.pop();
}
st.push(que[t].front());
que[t].pop();
}
}
return 0;
}
四、总结
关于栈的一道题,找到判断的条件即可。