首页 > 其他 > 详细

hdu 1702 ACboy needs your help again!

时间:2020-02-23 15:22:49      阅读:50      评论:0      收藏:0      [点我收藏+]

ACboy needs your help again!

技术分享图片

 

 技术分享图片

 

 思路:分两种容器,一个先进先出,一个先进后出,显然一个队列,一个栈,分好情况就行

代码:

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

using namespace std;

int main(){

    int m, n, num;
    char str1[15], str2[15];

    cin >> n;
    while (n--){
        scanf("%d %s", &m, str1);
        if (str1[2] == F){
            queue<int>q;
            while (m--){
                scanf("%s", str2);
                if (str2[0] == I){
                    cin >> num;
                    q.push(num);
                }
                else{
                    if (q.empty()){
                        cout << "None"<<endl;
                    }
                    else{
                        cout << q.front() << endl;
                        q.pop();
                    }
                }

            }
        }
        if (str1[2] == L){
            stack<int>s;
            while(m--){
                scanf("%s", str2);
                if (str2[0] == I){
                    cin >> num;
                    s.push(num);
                }
                else{
                    if (s.empty()){
                        cout << "None" << endl;
                    }
                    else{
                        cout << s.top() << endl;
                        s.pop();
                    }
                }
            }
        }
    }


    system("pause");
    return 0;
}

 

hdu 1702 ACboy needs your help again!

原文:https://www.cnblogs.com/pcdl/p/12349896.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!