-
Notifications
You must be signed in to change notification settings - Fork 0
/
n10845.java
42 lines (41 loc) · 1.44 KB
/
n10845.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
32
33
34
35
36
37
38
39
40
41
42
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;
public class n10845 {
public static void main(String []args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
Queue<Integer> queue = new LinkedList<>();
int b = -1;
for(int t=0;t<n;t++) {
String input = br.readLine();
if(input.contains("push")) {
b = Integer.parseInt(input.split(" ")[1]);
queue.add(b);
}
if(input.contains("front")) {
if(queue.isEmpty()) System.out.println(-1);
else System.out.println(queue.peek());
}
if(input.contains("back")) {
if(queue.isEmpty()) System.out.println(-1);
else System.out.println(b);
}
if(input.contains("size")) {
System.out.println(queue.size());
}
if(input.contains("empty")) {
if(queue.isEmpty()) System.out.println(1);
else System.out.println(0);
}
if(input.contains("pop")) {
if(queue.isEmpty()) System.out.println(-1);
else {
System.out.println(queue.poll());
}
}
}
}
}