输入样例:
10
push 6
empty
query
pop
empty
push 3
push 4
pop
query
push 6
输出样例:
NO
6
YES
4
import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);int m = sc.nextInt();int[] q = new int[100010];int hh = 0; //头int tt = -1;//尾while (m-- > 0){String s = sc.next();if (s.equals("push")){int x = sc.nextInt();q[++tt] = x;} else if (s.equals("pop")){hh++;} else if (s.equals("empty")){if (hh<=tt) System.out.println("NO");else System.out.println("YES");} elseSystem.out.println(q[hh]);}}
}