论我的一篇代码在 Dev-C++ 上没问题,但在洛谷上有问题( \text\color{7f00FF}{Runtime Error} )这件事
代码:
#include<bits/stdc++.h>
using namespace std;
#define maxNum 25
int n;
int __time__[5];
int qtm;
int var[26];
int p[maxNum];
vector<string> prg[maxNum];
deque<int> readyQ;
queue<int> blockQ;
bool locked;
string s;
const char assign = '=', output = 'i', _lock = 'c', unlock = 'l', _end = 'd';
void execute(int i)
{
int t = qtm, v = 0;
while(t)
{
string cur;
cur = prg[i][p[i]];
switch (cur[2])
{
case assign:
{
t -= __time__[0];
v = cur[4] - '0';
if(cur.size() == 6)
{
v = v * 10 + cur[5] - '0';
}
var[cur[0] - 'a'] = v;
break;
}
case output:
{
t -= __time__[1];
printf("%d: %d\n", i, var[cur[6]-'a']);
break;
}
case _lock:
{
t -= __time__[2];
if(locked)
{
blockQ.push(i);
return;
}
else
{
locked = 1;
}
break;
}
case unlock:
{
t -= __time__[3];
locked = 0;
if(!blockQ.empty())
{
int u = blockQ.front();
blockQ.pop();
readyQ.push_front(u);
}
break;
}
case _end:
{
return;
break;
}
}
p[i]++;
}
readyQ.push_back(i);
}
int main()
{
int T;
cin >> T;
while(T--)
{
cin >> n;
for(int i=0;i<5;i++)
{
cin >> __time__[i];
}
cin >> qtm;
memset(var, 0, sizeof(var));
for(int i=1;i<=n;i++)
{
prg[i].clear();
while(getline(cin, s))
{
prg[i].push_back(s);
if(prg[i].back() == "end")
{
break;
}
}
readyQ.push_back(i);
}
memset(p, 0, sizeof(p));
memset(var, 0, sizeof(var));
locked = 0;
while(!readyQ.empty())
{
int pid = readyQ.front();
readyQ.pop_front();
execute(pid);
}
if(T)
{
cout << endl;
}
}
return 0;
}
输入:
1
3 1 1 1 1 1 1
a = 4
print a
lock
b = 9
print b
unlock
print b
end
a = 3
print a
lock
b = 8
print b
unlock
print b
end
b = 5
a = 17
print a
print b
lock
b = 21
print b
unlock
print b
end
理想输出:
1: 3
2: 3
3: 17
3: 9
1: 9
1: 9
2: 8
2: 8
3: 21
3: 21