-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path집합.java
More file actions
47 lines (40 loc) · 1.56 KB
/
집합.java
File metadata and controls
47 lines (40 loc) · 1.56 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static HashSet<Integer> set = new HashSet<>();
static List<Integer> defaultNum = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20);
static int M;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
M = Integer.parseInt(br.readLine());
int now = 0;
for (int i = 0; i < M; i++) {
st = new StringTokenizer(br.readLine());
String tmp = st.nextToken();
// System.out.println(i);
if(!tmp.equals("all") && !tmp.equals("empty"))
now = Integer.parseInt(st.nextToken());
if("add".equals(tmp)){
set.add(now);
}else if("remove".equals(tmp)){
set.remove(now);
}else if("check".equals(tmp)){
if(set.contains(now)){
sb.append("1\n");
}else sb.append("0\n");
}else if("toggle".equals(tmp)){
if(set.contains(now)){
set.remove(now);
}else set.add(now);
}else if("all".equals(tmp)){
set.addAll(defaultNum);
}else if("empty".equals(tmp)){
set.clear();
}
}
System.out.println(sb);
}
}