eolymp
Задачи

Дек с защитой от ошибок

опубликовано 27.01.2022, 13:41:22

6130 has the same solution

include <iostream>

include <deque>

using namespace std; int main() { string n; long long m; deque<long long>v; while(cin>>n){ if(n=="push_back"){ cin>>m; v.push_back(m); cout<<"ok"<<endl; } else if(n=="push_front"){ cin>>m; v.push_front(m); cout<<"ok"<<endl; } else if(n=="pop_back"){ if(v.size()==0){ cout<<"error"<<endl; } else{ cout<<v.back()<<endl; v.pop_back(); } } else if(n=="pop_front"){ if(v.size()==0){ cout<<"error"<<endl; } else{ cout<<v.front()<<endl; v.pop_front(); } } else if(n=="size"){ cout<<v.size()<<endl; } else if(n=="clear"){ v.clear(); cout<<"ok"<<endl; } else if(n=="front"){ if(v.size()==0){ cout<<"error"<<endl; } else cout<<v.front()<<endl; } else if(n=="back"){ if(v.size()==0){ cout<<"error"<<endl; } else cout<<v.back()<<endl; } else if(n=="exit"){ cout<<"bye"; return 0; } } }