ACMACboy needs your help again!

Posted karshey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ACMACboy needs your help again!相关的知识,希望对你有一定的参考价值。

在这里插入图片描述
在这里插入图片描述
输入样例:

4
4 FIFO
IN 1
IN 2
OUT
OUT
4 FILO
IN 1
IN 2
OUT
OUT
5 FIFO
IN 1
IN 2
OUT
OUT
OUT
5 FILO
IN 1
IN 2
OUT
IN 3
OUT

输出样例:

1
2
2
1
1
2
None
2
3

没看题,直接看样例。
IN 后面跟着的数字可以是多位数,所以不要用string转化,直接int输入。

#include<iostream>
#include<queue> 
#include<stack>
#include<string>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		int m;
		cin>>m;
		string a;
		cin>>a;
		getchar();
		
		queue<int>q;
		stack<int>s;
		int flag;
		if(a[2]=='F')//queue
		{
			flag=0;			
		}
		else if(a[2]=='L') //stack
		{
			flag=1;			
		}
		
		for(int i=0;i<m;i++)
		{
			cin>>a;
			if(a[0]=='I')
			{
				int temp;
				cin>>temp;
				if(flag==0) q.push(temp);
				else s.push(temp);
			}
			else if(a[0]=='O')
			{
				if(flag==0) 
				{
					if(q.size()) 
					{
						cout<<q.front()<<endl;
						q.pop();
					}
					else cout<<"None"<<endl;
				}
				else if(flag==1) 
				{
					if(s.size()) 
					{
						cout<<s.top()<<endl;
						s.pop();
					}
					else cout<<"None"<<endl;
				}
			}
		}
	}
	
	return 0;
}

以上是关于ACMACboy needs your help again!的主要内容,如果未能解决你的问题,请参考以下文章

hdu1712 ACboy needs your help

ACboy needs your help-分组背包模板题

hdu1702 ACboy needs your help again!

HDU 1702 ACboy needs your help again!

Hdu 1702 ACboy needs your help again!

hdu1702 ACboy needs your help again!