ACboy needs your help again! hdu-1702 C++
阿新 • • 發佈:2021-01-25
考察棧與佇列
#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;
}