hdu1702 list or stack+queue

简介: http://acm.hdu.edu.cn/showproblem.php?pid=1702 #include<iostream>#include<cstdio>#include<cstring>#include<list>using namespace std;int main(){ // freopen("1.tx

http://acm.hdu.edu.cn/showproblem.php?pid=1702

#include<iostream>
#include<cstdio>
#include<cstring>
#include<list>
using namespace std;
int main()
{
   // freopen("1.txt","r",stdin);
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int m,i,x;
        list<int>li;
        li.clear();
        char s[10],ss[10];
        scanf("%d %s",&m,s);
        if(strcmp(s,"FIFO")==0)
        {
            for(i=0; i<m; i++)
            {
                scanf("%s",ss);
                if(strcmp(ss,"IN")==0)
                {
                    cin>>x;
                    li.push_back(x);
                }
                else
                {
                    if(li.empty())
                        cout<<"None"<<endl;
                    else
                    {
                        cout<<li.front()<<endl;
                        li.pop_front();
                    }
                }
            }
        }
        else
        {
            for(i=0; i<m; i++)
            {
                scanf("%s",ss);
                if(strcmp(ss,"IN")==0)
                {
                    cin>>x;
                    li.push_back(x);
                }
                else
                {
                    if(li.empty())
                        cout<<"None"<<endl;
                    else
                    {
                        cout<<li.back()<<endl;
                        li.pop_back();
                    }
                }
            }
        }
    }
    return 0;
}

  

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<queue>
using namespace std;
int main()
{
   // freopen("1.txt","r",stdin);
    int n,x,m;
    char s[10],ss[10];
    stack<int>st;
    queue<int>q;
    scanf("%d",&n);
    while(n--)
    {
        while(!st.empty())
            st.pop();
        while(!q.empty())
            q.pop();
        scanf("%d %s",&m,s);
        if(strcmp(s,"FILO")==0)
        {
            for(int i=0; i<m; i++)
            {
                scanf("%s",ss);
                if(strcmp(ss,"IN")==0)
                {
                    cin>>x;
                    st.push(x);
                }
                else
                {
                    if(st.empty())
                        cout<<"None"<<endl;
                    else
                    {
                        cout<<st.top()<<endl;;
                        st.pop();
                    }
                }
            }
        }
        else
        {
            for(int i=0; i<m; i++)
            {
                scanf("%s",ss);
                if(strcmp(ss,"IN")==0)
                {
                    cin>>x;
                    q.push(x);
                }
                else
                {
                    if(q.empty())
                        cout<<"None"<<endl;
                    else
                    {
                        cout<<q.front()<<endl;
                        q.pop();
                    }
                }
            }
        }
    }
    return 0;
}

  

目录
相关文章
|
2月前
|
存储 安全 Java
java集合框架及其特点(List、Set、Queue、Map)
java集合框架及其特点(List、Set、Queue、Map)
|
2月前
|
安全 Java API
Java并发 - J.U.C并发容器类 list、set、queue
Queue API 阻塞是通过 condition 来实现的,可参考 Java 并发 - Lock 接口 ArrayBlockingQueue 阻塞 LinkedBlockingQueue 阻塞 ArrayQueue 非阻塞 LinkedQueue 非阻塞
|
2月前
|
编译器 C++ 容器
STL常用之vector,list,stack,queue,deque总结与对比
STL常用之vector,list,stack,queue,deque总结与对比
|
5月前
|
存储 算法 Java
【Java 集合框架API接口】Collection,List,Set,Map,Queue,Deque
【Java 集合框架API接口】Collection,List,Set,Map,Queue,Deque
|
11月前
|
存储 Dart 数据处理
Dart中常用的集合类型List、Set、Map、Queue
Dart中常用的集合类型List、Set、Map、Queue
|
11月前
|
存储 Java
从上到下打印二叉树 Java代码实现(利用Queue和List实现)
从上到下打印二叉树 Java代码实现(利用Queue和List实现)
68 0
|
存储 算法 C++
STL——list、stack与queue
STL——list、stack与queue
|
存储 安全 算法
《我要进大厂》- Java集合夺命连环14问,你能坚持到第几问?(集合概述 | List | Set | Queue)
《我要进大厂》- Java集合夺命连环14问,你能坚持到第几问?(集合概述 | List | Set | Queue)
《我要进大厂》- Java集合夺命连环14问,你能坚持到第几问?(集合概述 | List | Set | Queue)
|
算法 C#
【愚公系列】2021年11月 C#版 数据结构与算法解析 Stack和List性能分析
【愚公系列】2021年11月 C#版 数据结构与算法解析 Stack和List性能分析
169 0
|
存储 安全 算法
Vector和Stack源码分析/List集合的总结
这篇文章算是在这list接口下的集合的最后一篇了,前面ArrayList、LinkedList都已经讲解完了,剩下就Vector和Vector的子类Stack啦。继续努力。一步一个脚印,
101 0