STL——管道一

7 篇文章 0 订阅

Problem B: STL——管道一Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 2764 Solved: 1625
[Submit][Status]Description现在有一个管道,这个管道是垂直的可以容纳许多字符串。我们定义如下操作。
1.插入 将一个字符串压入管道中,新压入的字符串位于管道的最上方。
2.查询并且删除 输出管道中最低端的字符串,并且将该字符串删除,删除之后原来位于第二低的字符串到了最低端,如果管道为空,输出-1
3.将管道清空

Input第一行为一个整数Q 不超过1000
之后Q行 每行首先一个整数 代表操作 1 2 3 分别对应三种操作
如果操作为一 之后跟随一个字符串 只包含小写字母

Output每一个2操作输出相应的答案

Sample Input
6
1 aabb
2
1 aaccvb
2
1 ffvv
2
Sample Output
aabb
aaccvb
ffvv
HINT用STL的queue容易解决

Append Code

#include <iostream>
#include <deque>
#include<list>
#include <string>
using namespace std;
int main()
{
    deque<string>s;
    int n;
    while(cin>>n&&n<=1000){
      while(n--){
        int a;
        cin>>a;
        if(a==1){
            string s1;
            cin>>s1;
            s.push_front(s1);
        }
//        else if(a==2){
//            string s2;cin>>s2;
//            s.push_back(s2);
//        }
        else if(a==2){
            if(s.empty())
                cout<<-1<<endl;
            else{
              cout<<s.back()<<endl;
                s.pop_back();
            }
        }
//        else if(a==4){
//            if(s.empty())
//                cout<<-1<<endl;
//            else{
//              cout<<s.front()<<endl;
//            }
//        }
//        else if(a==5){
//            if(s.empty())
//                cout<<-1<<endl;
//            else{
//                s.pop_back();
//            }
//        }
//        else if(a==6){
//            if(s.empty())
//                cout<<-1<<endl;
//            else{
//                s.pop_front();
//            }
//        }
        else if(a==3){
            while(!s.empty()){
                s.clear();
            }
        }
      }
    }
}
在这里插入代码片
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值