• Hdu-1072


    题目描述:

    首先输入一个N;代表测试数据的个数;

    然后每个测试数据的开头第一行输入一个n和一个命令(FIFO或FILO<就是先进先出或先进后出>)

    然后是该测试数据的n行,每行包括“IN”加一个数字(代表入栈或入队)或者一个“OUT”(代表出队或出栈)

    若已经是空的了遇到“OUT”命令时输出“None”;

    其实就是c++STL的队列和栈的简单应用;

    代码如下:

     ************************************************************************/

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int n;
        cin>>n;
        while(n--){
            int com_num,typ_num;
            cin>>com_num;
            string com;
            cin>>com;
            if(com=="FIFO"){
                queue<int> q;
                for(int i=0;i<com_num;i++){
                    cin>>com;
                    if(com=="IN"){
                        cin>>typ_num;
                        q.push(typ_num);
                    }
                    if(com=="OUT"){
                        if(q.empty()){
                            cout<<"None"<<endl;
                        }
                        else{
                            cout<<q.front()<<endl;
                            q.pop();
                        }
                    }
                }
            }
            if(com=="FILO"){
                stack<int> st;
                for(int i=0;i<com_num;i++){
                    cin>>com;
                    if(com=="IN"){
                        cin>>typ_num;
                        st.push(typ_num);
                    }
                    if(com=="OUT"){
                        if(st.empty()){
                            cout<<"None"<<endl;
                        }
                        else{
                            cout<<st.top()<<endl;
                            st.pop();
                        }
                    }
                }
            }
        }
        return 0;
    }

  • 相关阅读:
    MongoDB 常用的基础命令
    window.crypto 生成随机数
    正则去除object中key的引号
    git 常用操作命令
    常用的用于操作 css 的方法
    angular ViewChild ContentChild 系列的查询参数
    angular 键盘事件绑定与过滤
    mysql性能优化(A)
    移动硬盘写保护处理
    expdp/impdp导入导出
  • 原文地址:https://www.cnblogs.com/sunowsir/p/6804919.html
Copyright © 2020-2023  润新知