1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include<cstdio> #include<cstring> #include<cctype> #include<queue> using namespace std; const int maxn=1010; bool locked; char pro[maxn][10]; int n,tq,c[5],var[26],ip[maxn]; deque<int> ready; queue<int> block; void run(int pid){ int q=tq; while(q>0){ char *p=pro[ip[pid]]; switch(p[2]){ case '=': var[p[0]-'a']=isdigit(p[5])?(p[4]-'0')*10+p[5]-'0':p[4]-'0'; q-=c[0]; break; case 'i': printf("%d: %d\n",pid+1,var[p[6]-'a']); q-=c[1]; break; case 'c': if(locked){block.push(pid);return;} locked=true; q-=c[2]; break; case 'l': locked=false; if(!block.empty()){ int pid2=block.front(); block.pop(); ready.push_front(pid2); } q-=c[3]; break; case 'd': return; } ++ip[pid]; } ready.push_back(pid); } int main(){ int t; scanf("%d",&t); while(t--){ scanf("%d%d%d%d%d%d%d\n",&n,&c[0],&c[1],&c[2],&c[3],&c[4],&tq); memset(var,0,sizeof(var)); int line=0; for(int i=0;i<n;++i){ fgets(pro[line++],maxn,stdin); ip[i]=line-1; while(pro[line-1][2]!='d') fgets(pro[line++],maxn,stdin); ready.push_back(i); } locked=false; while(!ready.empty()){ int pid=ready.front(); ready.pop_front(); run(pid); } if(t) printf("\n"); } return 0; }
|