思路:注意下溢的时候退出就行
import java.util.LinkedList;import java.util.Queue;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); Queue que = new LinkedList(); for(int i=0; i<n; i++) { int num = in.nextInt(); if(num == 1) { int m = in.nextInt(); //进队 que.offer(m); } else if(num == 2) { if(que.isEmpty()) { System.out.PRintln("no"); return; } else //出队并删除 System.out.println(que.poll()); } else if(num == 3) { System.out.println(que.size()); } } } }
新闻热点
疑难解答