L2-1 包装机 (2021天梯赛)

L2-037 包装机 (25 分)

AC代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
	queue<char>  g[110];
	stack<char> lz;
	int n,m,s;
	cin>>n>>m>>s;
	char c;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>c;
			g[i].push(c);
		}
	}
	int t;
	while(cin>>t)
	{
		if(t==-1)
			return 0;
		if(t==0 && !lz.empty() )
		{
			cout<<lz.top();
			lz.pop();
		}
		else if(t)
		{
			if(!g[t].empty())
			{
				if(lz.size()==s)
				{
					cout<<lz.top();
					lz.pop();
				}
				lz.push(g[t].front());
				g[t].pop();
			}
		}
	}
	return 0;
 } 
posted @ 2021-05-03 19:50  斯文~  阅读(156)  评论(0)    收藏  举报

你好!