-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10845.java
31 lines (27 loc) · 1012 Bytes
/
10845.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
Queue<Integer> que = new LinkedList<Integer>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
int back=-1;
for(int i=0; i<num; i++) {
String[] input = br.readLine().split(" ");
if(input[0].contains("push")) {
back=Integer.parseInt(input[1]);
que.offer(back);
}else if(input[0].equals("pop")){
System.out.println(que.isEmpty()?-1:que.poll());
}else if(input[0].equals("size")) {
System.out.println(que.size());
}else if(input[0].equals("empty")) {
System.out.println(que.isEmpty()?1:0);
}else if(input[0].equals("front")) {
System.out.println(que.isEmpty()?-1:que.peek());
}else if(input[0].equals("back")) {
System.out.println(que.isEmpty()?-1:back);
}
}
}
}