8 solutions
-
0
双向队列的基本操作
#include<bits/stdc++.h> #include<string> int t,x; using namespace std; int main(){ std::ios::sync_with_stdio(false); deque <int> num;//操作双向队列 queue <int> error;//记录error命令行数的队列 cin>>t; for(int i=1;i<=t;i++){ string order; cin>>order; if(order=="LIN"){//从头部入队一个元素 cin>>x; num.push_front(x); }else if(order=="RIN"){//从尾部入队一个元素 cin>>x; num.push_back(x); }else if(order=="ROUT"){//从头部出队一个元素 if(!num.empty()) num.pop_back(); else error.push(i); }else if(order=="LOUT"){//从尾部出队一个元素 if(!num.empty()) num.pop_front(); else error.push(i); } } while(!num.empty()){ cout<<num.front()<<" "; num.pop_front(); } cout<<endl; while(!error.empty()){ cout<<error.front()<<" "<<"ERROR"<<endl;; error.pop(); } return 0; }
Information
- ID
- 1125
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 6
- Tags
- # Submissions
- 136
- Accepted
- 43
- Uploaded By