欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

HDU 1702 ACboy needs your help again!(栈和队列的简单应用)

程序员文章站 2022-07-16 09:46:50
...

题目链接:HDU 1702 ACboy needs your help again!
HDU 1702	ACboy needs your help again!(栈和队列的简单应用)
HDU 1702	ACboy needs your help again!(栈和队列的简单应用)

啥错都范,return 0; 忘写了。。。

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

int main()
{
	int t,n,m;
	cin>>t;
	string s,com;
	queue<int> q;
	stack<int> st;
	while(t--)
	{
		while(!q.empty()) q.pop();
		while(!st.empty()) st.pop();
		
		cin>>n>>s;
		while(n--)
		{
			cin>>com;
			if(s=="FIFO")
			{
				if(com=="IN")
				{
					cin>>m;
					q.push(m);
				}
				else if(com=="OUT")
				{
					if(!q.empty())
					{
						printf("%d\n",q.front());
						q.pop();
					} 	
					else
						printf("None\n");
				}
			}
			else if(s=="FILO")
			{
				if(com=="IN")
				{
					cin>>m;
					st.push(m);
				}
				else if(com=="OUT")
				{
					if(!st.empty())
					{
						printf("%d\n",st.top());
						st.pop();
					}	
					else
						printf("None\n");
				}
			}	
		}
	}
	
	return 0;
}