Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<queue>
- using namespace std;
- main()
- {
- queue <int> Q;
- int n;
- cin>>n;
- for(int i=0; i<n; i++)
- {
- int x;
- cin>>x;
- if(x == 1)
- {
- cout<<Q.size()<<endl;
- }
- if(x == 2)
- {
- if(!Q.empty()) cout<<"NO";
- else cout<<"YES";
- cout<<endl;
- }
- if(x == 3)
- {
- int a;
- cin>>a;
- Q.push(a);
- }
- if(x == 4)
- {
- if(!Q.empty()) Q.pop();
- }
- if(x == 5)
- {
- if(!Q.empty()) cout<<Q.front();
- else cout<<"-1";
- cout<<endl;
- }
- if(x == 6)
- {
- if(!Q.empty()) cout<<Q.back();
- else cout<<"-1";
- cout<<endl;
- }
- }
- }
Add Comment
Please, Sign In to add comment