2 solutions
-
-2
第二种:c++
#include<bits/stdc++.h> using namespace std; queue<int> q; int main() { int n; cin>>n; for(int i=1;i<=n;i++) { string a; cin>>a; if(a=="push") { int x; cin>>x; q.push(x); } if(a=="pop") q.pop(); if(a=="empty") { if(q.empty()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } if(a=="query") { cout<<q.front()<<endl; } } return 0; }
-
-2
数组:c++
#include<bits/stdc++.h> using namespace std; const int N=100010; int q[N]; int hh=0,tt=-1; int main() { int n; cin>>n; while(n--) { string s; cin>>s; if(s=="push") { int t; cin>>t; q[++tt]=t; } else if(s=="pop") { hh++; } else if(s=="empty") { if(hh<=tt) { cout<<"NO"<<endl; } else { cout<<"YES"<<endl; } } else { cout<<q[hh]<<endl; } } return 0; }
- 1
Information
- ID
- 162
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 1
- Tags
- (None)
- # Submissions
- 77
- Accepted
- 20
- Uploaded By