Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <deque>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0), cout.tie(0);
- string s;
- cin>>s;
- deque <char> dq;
- int i=0;
- while(s[i]!='\0')
- dq.push_back(s[i++]);
- int q;
- cin>>q;
- int tip_op;
- char c;
- bool rev=true;
- while(q--)
- {
- cin>>tip_op;
- if(tip_op==5)
- rev=!rev;
- else
- if(tip_op>2)
- {
- if((tip_op==3&&!rev)||(tip_op==4&&rev))
- dq.pop_back();
- else
- dq.pop_front();
- }
- else
- {
- cin>>c;
- if((tip_op==1&&!rev)||(tip_op==2&&rev))
- dq.push_back(c);
- else
- dq.push_front(c);
- }
- }
- s.clear();
- while(!dq.empty())
- if (rev)
- s+=dq.front(),dq.pop_front();
- else
- s+=dq.back(),dq.pop_back();
- cout<<s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement