-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBAEKJOON_11723
More file actions
58 lines (51 loc) · 1.67 KB
/
BAEKJOON_11723
File metadata and controls
58 lines (51 loc) · 1.67 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.*;
import java.util.*;
public class Test {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
ArrayList<Integer> list = new ArrayList<>();
int M = Integer.parseInt(br.readLine());
StringTokenizer st;
for(int i=0; i<M; i++){
st = new StringTokenizer(br.readLine());
String str = st.nextToken();
Integer num=0;
if (st.hasMoreTokens()) {
num = Integer.parseInt(st.nextToken());
}
if(str.equals("add")){
if (!list.contains(num)) {
list.add(num);
}
}else if(str.equals("remove")){
if (list.contains(num)) {
list.remove(num);
}
}else if(str.equals("check")){
if (list.contains(num)) {
bw.write("1");
bw.newLine();
}else{
bw.write("0");
bw.newLine();
}
}else if(str.equals("toggle")){
if (list.contains(num)) {
list.remove(num);
}else{
list.add(num);
}
} else if (str.equals("all")) {
list.clear();
for(int j=1; j<=20; j++){
list.add(j);
}
}else{
list.clear();
}
}
bw.flush();
bw.close();
}
}