AcWing 3464. 包装机
原题链接
中等
作者:
papapiu
,
2021-08-27 22:06:47
,
所有人可见
,
阅读 258
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
const int N = 1010;
queue<char> q[N];
stack<char> sta;
int main()
{
int n,m,k;
cin>>n>>m>>k;
string c;
for (int i = 1; i <= n; i ++ ){
cin>>c;
for(int j = 0;j<c.size();j++){
q[i].push(c[j]);
}
}
int x;
while(cin>>x,x!=-1){
if(!x){
if(sta.size()){
cout<<sta.top();
sta.pop();
}
}else{
if(q[x].size()){
if(sta.size()==k){
cout<<sta.top();
sta.pop();
}
sta.push(q[x].front());
q[x].pop();
}
}
}
return 0;
}