本题有多组输入数据,你必须处理到EOF为止。
请对输入数据中每条POP指令的结果依次输出一行结果。
用STL的queue容易解决
한국어< 中文 فارسی English ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin
#include <iostream> #include <queue> using namespace std; int main() { int m, n; while( cin >> n) { cin >> m; queue <int >Q[n+1]; for(int p = 0; p < m; p++ ) { string s; cin >> s; if(s == "INIT") for(int i = 0; i <= n; i++) while(!Q[i].empty()) Q[i].pop(); if(s == "POP" ) { int i, t; cin >> i >> t; if(Q[i].empty()) cout << "NULL" << endl; else { queue<int> q1; cout << Q[i].front() << endl; Q[i] = q1; } } if(s == "PUSH") { int i, j, t; cin >> i >> j >> t; for(int k = 0; k < t; k++) Q[i].push(j); } } } }