-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj10845.java
More file actions
35 lines (29 loc) · 1.04 KB
/
boj10845.java
File metadata and controls
35 lines (29 loc) · 1.04 KB
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
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class boj10845 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int input = 0;
Queue<Integer> q = new LinkedList<>();
for (int i = 0; i < N; i++) {
String str = sc.next();
if (str.contains("push")) {
input = sc.nextInt();
q.add(input);
} else if (str.contains("front")) {
System.out.println(q.isEmpty() ? -1 : q.peek());
} else if (str.contains("back")) {
System.out.println(q.isEmpty() ? -1 : input);
} else if (str.contains("size")) {
System.out.println(q.size());
} else if (str.contains("pop")) {
System.out.println(q.isEmpty() ? -1 : q.poll());
} else if (str.contains("empty")) {
System.out.println(q.isEmpty() ? 1 : 0);
}
}
sc.close();
}
}