题目意思很简单,利用stl里的stack进行模拟即可,需要注意,当某一个轨道为空时不能继续向框里添加东西,否则只能拿20分。。
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
int main()
{
queue<char> a[110];
stack<char> b;
int n, k, m, x;
string d;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
string c;
cin >> c;
for (int j = 0; c[j]; j++)
a[i + 1].push(c[j]);
}
while (cin >> x && x != -1) {
if (x == 0 && !b.empty())d += b.top(), b.pop();
else {
if (a[x].empty())continue;
if (b.size() == k)d += b.top(), b.pop();
auto e = a[x].front(); a[x].pop();
b.push(e);
}
}
cout << d << endl;
return 0;
}