0
点赞
收藏
分享

微信扫一扫

L2-037 包装机 (25 分)(C/C++)

E_topia 2023-11-11 阅读 48

L2-037 包装机 (25 分)(C/C++)_ios

L2-037 包装机 (25 分)(C/C++)_#include_02

输入样例:

3 4 4
GPLT
PATA
OMSA
3 2 3 0 1 2 0 2 2 0 -1

输出样例:

MATA

这道题需要注意的就是当框空的时候,按下0是什么都不会发生的。当对应轨道空的时候,按下对应轨道的数字也是什么都不会发生的当对应轨道不为空,但是框满的时候,需要先把框顶的弹出来,再装进去新的。

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
#include<stack>
#define llu unsigned long long
using namespace std;

queue<char> d[1100];
stack<char> q;
int main()
{
	//cout << fixed << setprecision(0);
	//cout << setw(8) << setiosflags(ios::left);
	int n,m,s;
	cin >> n >> m >> s ;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			char x;
			cin >> x ;
			d[i].push(x);
		}
	}
	/*for(int i=1;i<=n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cout << d[i].front();
			d[i].pop();
		}
		cout << endl ;
	}*/
	int t;
	while(cin >> t , t!=-1)
	{
		if(t==0){
			if(!q.empty())
			{
				cout << q.top() ;
				q.pop();
			}
	 	}
	 	else {
	 		if(!d[t].empty()){
	 			int ss=q.size();
				if(ss==s){
					cout << q.top() ;
					q.pop();
				}
				q.push(d[t].front());
				d[t].pop();
			}
		}
	}
	return 0;
}

举报

相关推荐

0 条评论