zoukankan      html  css  js  c++  java
  • A

    - 题目大意

        给出了先进先出和先进后出的两种结构,分别对应队列和栈,并且每种均给出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;
    }
    

      

  • 相关阅读:
    Linux-vim
    [转载]关于eve模拟器上的VPS配置问题
    [转载]cisco 出现%Error opening tftp://255.255.255.255/cisconet.cfg解决方法
    CCNA-NAT
    CCNA-DHCP
    CCNA-ACL
    CCNA-OSPF 配置
    CCNA-OSPF 基础
    枚举的应用
    带索引的遍历
  • 原文地址:https://www.cnblogs.com/alpacadh/p/8438469.html
Copyright © 2011-2022 走看看