#include<iostream> #include<algorithm> #include<string> #include<sstream> #include<vector> #include<queue> #include<cstring> using namespace std; const int maxn = 10001; //uva210:题意 模拟n个程序的并行执行,有赋值,打印,lock,unlock,end五种。 //输入n,t1,t2,t3,t4,t5,Q; int n, t1, t2, t3, t4, t5, Q; deque<int>wait;//等待队列 deque<int>stop;//阻止队列 int num[maxn]; int main(void) { cin >> n >> t1 >> t2 >> t3 >> t4 >> t5 >> Q; string s; int id = 0; while(getline(cin,s)) { char c = s[2]; while (Q) { if (c == '='&&Q-t1>=0) { int ch = s[1]; num[ch-'a']==(int)s } } } return 0; } #include<iostream> #include<stack> #include<deque> #include<vector> int n, t1, t2, t3, t4, t5, Q; deque<int>wait;//阻塞队列 deque<int>ready;//等待队列 vector<string> str;//存储执行语句 int var[101];//存储变量 int block; void run(int i)//在ready队列中执行到第i个(str下标)的命令 { int time = Q; char c; while(time>0) { c = str[i][2]; if(c=='=') { time -= t1; //赋值范围为0-99 var[str[i][0] - 'a'] = isdigit(str[i][4]) ? (int)str[i][4] * 10 + str[i][5] : (int)str[i][5]; } else if(c=='i') { time -= t2; cout << i<<' ' << var[str[i][6]] << endl; } else if(c=='c') { if(!ready.empty()&&block) { wait.push_back(i); return; } time -= t3; block = 1; } else if(c=='l') { if(!wait.empty()) { ready.push_back(wait.front()); wait.pop_front(); } block = 0; time -= t4; } else { time -= t5; return; } } } int main() { //输入 cin >> n >> t1 >> t2 >> t3 >> t4 >> t5 >> Q; string s; for(int i=1;i<=n;i++) { while(getline(cin,s)) { str[i] = s; ready.push_front(i);//str的下标传入到ready中,之后处理 } } //处理 while (!ready.empty()) { int x = ready.front(); ready.pop_front(); // cout<<x<<" "; run(x); // 依次执行准备列队的队头 } }
标签:队列,并行程序,双端,t2,t1,int,str,UVA210,include From: https://www.cnblogs.com/xingxingli/p/17522062.html