题目链接:https://www.acwing.com/problem/content/831/
数组模拟队列
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N=1e5+10; 4 int a[N]; 5 int h=0,t=0,n; 6 int main() 7 { 8 cin>>n; 9 while(n--){ 10 string s; 11 int x; 12 cin>>s; 13 if(s=="push"){ 14 cin>>x; 15 a[++t]=x; 16 }else if(s=="pop"){ 17 ++h; 18 }else if(s=="empty"){ 19 if(h>=t){ 20 cout<<"YES"<<endl; 21 }else{ 22 cout<<"NO"<<endl; 23 } 24 }else if(s=="query"){ 25 cout<<a[h+1]<<endl; 26 } 27 } 28 return 0; 29 }