1. 程式人生 > 其它 >ACboy needs your help again! hdu-1702 C++

ACboy needs your help again! hdu-1702 C++

技術標籤:HDU佇列c++

題目連結

在這裡插入圖片描述

考察棧與佇列

#include<iostream>
#include<string>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        int m;
        string str;
        int temp;
        cin >> m;
        cin >>
str; if (str=="FIFO") { queue<int> dq; for (int i = 0; i < m; i++) { cin >> str; if (str=="IN") { cin >> temp; dq.push(
temp); } else if (str=="OUT") { if (dq.empty()) { cout << "None"; } else { cout <<
dq.front(); dq.pop(); } cout << endl; } } } else if (str == "FILO") { stack<int> st; for (int i = 0; i < m; i++) { cin >> str; if (str == "IN") { cin >> temp; st.push(temp); } else if (str == "OUT") { if (st.empty()) { cout << "None"; } else { cout << st.top(); st.pop(); } cout << endl; } } } } return 0; }