fork download
  1. #include <iostream>
  2. #include <queue>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. queue<int>p;
  9. int n;
  10. cin>>n;
  11. while(n--){
  12. string g;
  13. cin>>g;
  14. int o;
  15. if(g=="push"){
  16. cin>>o;
  17. p.push(o);
  18. }else if(g=="pop"){
  19. p.pop();}
  20. else if(g=="front"){
  21. cout<<p.front()<<endl;}
  22. else if(g=="back"){
  23. cout<<p.back()<<endl;
  24. }
  25. }
  26. }
Success #stdin #stdout 0s 5324KB
stdin
15
push 5
front
back
push 6
front
back
push 3
front
back
pop
front
back
pop
front
back
stdout
5
5
5
6
5
3
6
3
3
3