8 solutions
-
1
#include <bits/stdc++.h> using namespace std; int main() { string a="LIN",b="RIN",c="LOUT",d="ROUT",m; int n,x; cin>>n; int temp=n; deque <int> s; queue <int> p; while(n--) { cin>>m; if(m==a) { cin>>x; s.push_front(x); } else if(m==b) { cin>>x; s.push_back(x); } else if(m==c) { if(!s.empty()) { s.pop_front(); } else p.push(temp-n+1); } else if(m==d) { if(!s.empty()) { s.pop_back(); } else p.push(temp-n); } } while(!s.empty()) { cout<<s.front(); s.pop_front(); s.empty()?cout:cout<<" "; } cout<<endl; while(!p.empty()) { cout<<p.front(); p.pop(); cout<<" ERROR"<<endl; } return 0; }
Information
- ID
- 1125
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 6
- Tags
- # Submissions
- 136
- Accepted
- 43
- Uploaded By