eolymp
Задачи

Очередь неограниченного размера

опубликовано 17.05.2022, 15:14:10

YASHMA IS COMINAA

include <iostream>

include <queue>

using namespace std; int main() { long n; long k; string s; queue<int>q; while(cin>>s) { if(s=="push") { cin>>n; q.push(n); cout<<"ok"<<endl; } if(s=="pop") { if(q.empty()==true) { cout<<"error"<<endl; } else{ cout<<q.front()<<endl; q.pop();} } if(s=="front") { if(q.empty()==true) { cout<<"error"<<endl; } else{ cout<<q.front()<<endl; } } if(s=="size") { cout<<q.size()<<endl; } if(s=="clear") { while(!q.empty()) { q.pop(); } cout<<"ok"<<endl; } if(s=="exit") { cout<<"bye"<<endl; break; } } }

опубликовано 22.05.2022, 17:29:46

include <iostream>

include <deque>

using namespace std; int main() { deque<int>v; string s; int n,k; while(1) { cin>>s; if(s=="push") { cin>>n; v.push_back(n); cout<<"ok"<<endl; } else if(s=="pop") { if(!v.empty()){ cout<<v.front()<<endl; v.pop_front(); } else{ cout<<"error"<<endl; } } else if(s=="front") { if(!v.empty()) cout<<v.front()<<endl; else cout<<"error"<<endl; } else if(s=="size") { cout<<v.size()<<endl; } else if(s=="clear") { cout<<"ok"<<endl; v.clear(); } else if(s=="exit") { cout<<"bye"<<endl; return 0; }

}

}