hdu 1702

来源:互联网 发布:离线运行unity3d游戏 编辑:程序博客网 时间:2024/06/07 15:09

题目大意:理解起来很简单,读者可以直接上OJ上面看

代码如下:

/* * 1702_1.cpp * *  Created on: 2013年8月7日 *      Author: Administrator *      为了能有章泽天这样的女朋友而不断努力。。。。 */#include <iostream>#include <stack>#include <queue>using namespace std;int main() {int t, m;string str;cin >> t;stack<int> p;queue<int> q;while (t--) {/** * 因为STL中的stack、queue没有专门的clear()函数 * 所以每次都要自己写清空stack、queue的函数 */while(!p.empty()){p.pop();}while(!q.empty()){q.pop();}cin >> m >> str;if (str == "FIFO") {for (int i = 0; i < m; ++i) {string cmd;int n;cin >> cmd;if (cmd == "IN") {cin >> n;q.push(n);} else if (cmd == "OUT") {if (!q.empty()) {int a = q.front();q.pop();cout << a << endl;} else {cout << "None" << endl;}}}} else {for (int i = 0; i < m; ++i) {string cmd;int n;cin >> cmd;if (cmd == "IN") {cin >> n;p.push(n);} else if (cmd == "OUT") {if (!p.empty()) {int a = p.top();p.pop();cout << a << endl;} else {cout << "None" << endl;}}}}}}