AcWing 829. 模拟队列--Jvav
原题链接
简单
作者:
domiso
,
2021-08-26 19:08:56
,
所有人可见
,
阅读 163
import java.util.*;
public class Main {
static int q[],hh,tt,N = 100010;
static {
q = new int[N];
hh = 0;
tt = -1;
}
static void push(int x){
q[++tt] = x;
}
static int pop(){
return q[hh++];
}
static int query(){
return q[hh];
}
static boolean empty(){
return hh > tt;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
while(m -- >= 0 ) {
String[] s = sc.nextLine().split(" ");
if(s[0].equals("push")) {
push(Integer.parseInt(s[1]));
}else if(s[0].equals("pop")) {
pop();
}else if(s[0].equals("empty")) {
if(empty()) System.out.println("YES");
else System.out.println("NO");
}else if(s[0].equals("query")) {
System.out.println(query());
}
}
}
}