A - ACboy needs your help again! (HDU - 1702)

Posted Alpacaddhh

tags:

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

- 题目大意

    给出了先进先出和先进后出的两种结构,分别对应队列和栈,并且每种均给出In和Out两类操作,如果是In,push进后面的数,如果是Out,输出栈顶(队首)。

- 解题思路

    对于给的命令判断,然后来决定是用队列还是栈。

- 代码

#include<iostream>
#include<stack>
#include<queue>

using namespace std;
int main()
{
	int n,x,b;
	char a[5];
	char c[5];
	cin >> n;
	while (n--)
	{
		cin >> x >> a;
		
		if (strcmp(a, "FIFO"))
		{
			stack<int>num;
			while (x--)
			{
				cin >> c;
				if (!strcmp(c, "IN"))
				{
					cin >> b;
					num.push(b);
				}
				else
				{
					if (num.empty())
					{
						cout << "None" << endl;
					}
					else
					{
						cout << num.top() << endl;
						num.pop();
					}
				}
			}
		}

			else
			{
				queue<int>sum;
				while (x--)
				{
				cin >> c;
				if (!strcmp(c, "IN"))
				{
					cin >> b;
					sum.push(b);
				}
				else
				{
					if (sum.empty())
					{
						cout << "None" << endl;
					}
					else
					{
						cout << sum.front() << endl;
						sum.pop();
					}
				}
			}
		}
	}
	return 0;
}

  

以上是关于A - ACboy needs your help again! (HDU - 1702)的主要内容,如果未能解决你的问题,请参考以下文章

hdu 1712 ACboy needs your help

ACboy needs your help(分组背包)

hdu1712 ACboy needs your help

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

hdu1702 ACboy needs your help again!

HDU 1702 ACboy needs your help again!