HDU1702 ACboy needs your help again! 题解

发布时间 2023-07-28 10:42:30作者: Miya555
#include <iostream>
#include <string>
#include <queue>
#include <stack>
using namespace std;
int t, n, m;


int main() {
    cin >> t;
    while (t--) {
        queue<int>q;
    stack<int>s;
        string op, str;
        cin >> n;
        cin >> op;
        if (op == "FIFO") {
            while (n--) {
                cin >> str;
                if (str == "IN") {
                    cin >> m;
                    q.push(m);
                } else {
                    if (q.empty()) {
                        cout << "None" << endl;

                    } else {
                        cout << q.front() << endl;
                        q.pop();
                    }
                }
            }
        }
        if (op == "FILO") {
            while (n--) {
                cin >> str;
                if (str == "IN") {
                    cin >> m;
                    s.push(m);
                } else {
                    if (s.empty()) {
                        cout << "None" << endl;
                    } else {
                        cout << s.top() << endl;
                        s.pop();
                    }
                }
            }
        }
    }

    return 0;
}