题目链接如下:
题目中给出的测试样例是错的,最前面需要给出case个数。
代码如下:
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <cstdlib>
// #define debug
int n, m, quant, kase;
int t[5], val[26], ip[11];
std::string str;
int main(){
#ifdef debug
freopen("0.txt", "r", stdin);
freopen("1.txt", "w", stdout);
#endif
scanf("%d", &n);
for (kase = 0; kase < n; ++kase){
std::deque<int> readyQ, blockedQ;
bool flag = true;
for (int i = 0; i < 26; ++i){
val[i] = 0;
}
for (int i = 0; i < 11; ++i){
ip[i] = 0;
}
printf("%s", kase ? "\n" : "");
scanf("%d", &m);
std::vector<std::vector<std::string> > lineVec(m + 1);
for (int i = 0; i < 5; ++i){
scanf("%d", &t[i]);
}
scanf("%d\n", &quant);
int pro = 1;
while (getline(std::cin, str)){
lineVec[pro].push_back(str);
if (str == "end"){
pro++;
if (pro == m + 1){
break;
}
}
}
for (int i = 1; i <= m; ++i){
readyQ.push_back(i);
}
while (1){
if (readyQ.empty()){
break;
}
int temp = readyQ.front();
readyQ.pop_front();
int tt = quant;
bool ff = true;
for (; tt > 0 && ip[temp] < lineVec[temp].size(); ip[temp]++){
std::string ss = lineVec[temp][ip[temp]];
if (ss[0] == 'p' && ss[1] == 'r'){
printf("%d: %d\n", temp, val[ss.back() - 'a']);
tt -= t[1];
} else if (ss[0] == 'l' && ss[1] == 'o'){
if (!flag){
blockedQ.push_back(temp);
ff = false;
break;
}
flag = false;
tt -= t[2];
} else if (ss[0] == 'u' && ss[1] == 'n'){
tt -= t[3];
flag = true;
if (!blockedQ.empty()){
readyQ.push_front(blockedQ.front());
blockedQ.pop_front();
}
} else if (ss[0] == 'e' && ss[1] == 'n'){
tt -= t[4];
ff = false;
} else {
tt -= t[0];
int loc = ss.find("=");
int value = atoi(ss.substr(loc + 1).c_str());
val[ss.front() - 'a'] = value;
}
}
if (ff){
readyQ.push_back(temp);
}
}
}
#ifdef debug
fclose(stdin);
fclose(stdout);
#endif
return 0;
}