• hdu 1702 ACboy needs your help again!


    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;
    }
  • 相关阅读:
    2019.7.28刷题统计
    2019.7.27刷题统计
    2019.7.26刷题统计
    2019.7.22刷题统计
    qdoj.xyz 6.18
    qdoj.xyz 6.17
    qdoj.xyz 6.16
    qdoj.xyz 6.15
    qdoj.xyz 6.14
    qdoj.xyz 6.13
  • 原文地址:https://www.cnblogs.com/pcdl/p/12349896.html
Copyright © 2020-2023  润新知