Centipede18

queue

Apr 14th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<queue>
  3.  
  4. using namespace std;
  5.  
  6. main()
  7. {
  8.     queue <int> Q;
  9.     int n;
  10.     cin>>n;
  11.     for(int i=0; i<n; i++)
  12.     {
  13.         int x;
  14.         cin>>x;
  15.         if(x == 1)
  16.         {
  17.             cout<<Q.size()<<endl;
  18.         }
  19.         if(x == 2)
  20.         {
  21.             if(!Q.empty()) cout<<"NO";
  22.             else cout<<"YES";
  23.             cout<<endl;
  24.         }
  25.         if(x == 3)
  26.         {
  27.             int a;
  28.             cin>>a;
  29.             Q.push(a); 
  30.         }
  31.         if(x == 4)
  32.         {
  33.             if(!Q.empty()) Q.pop();
  34.         }
  35.         if(x == 5)
  36.         {
  37.             if(!Q.empty()) cout<<Q.front();
  38.             else cout<<"-1";
  39.             cout<<endl;
  40.         }
  41.         if(x == 6)
  42.         {
  43.             if(!Q.empty()) cout<<Q.back();
  44.             else cout<<"-1";
  45.             cout<<endl;
  46.         }
  47.     }
  48. }
Add Comment
Please, Sign In to add comment