-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11723.java
More file actions
70 lines (62 loc) · 1.83 KB
/
11723.java
File metadata and controls
70 lines (62 loc) · 1.83 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
59
60
61
62
63
64
65
66
67
68
69
70
import java.io.*;
import java.util.*;
public class Main {
public static int M;
public static StringBuilder sb= new StringBuilder("");
public static int num;
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int M = Integer.parseInt(br.readLine());
num = 0;
for(int i=0;i<M;i++){
StringTokenizer st = new StringTokenizer(br.readLine());
switch (st.nextToken()){
case "add":
add(Integer.parseInt(st.nextToken()) - 1);
break;
case "remove":
remove(Integer.parseInt(st.nextToken()) - 1);
break;
case "check":
check(Integer.parseInt(st.nextToken()) - 1);
break;
case "toggle":
toggle(Integer.parseInt(st.nextToken()) - 1);
break;
case "all":
all();
break;
case "empty":
empty();
break;
}
}
System.out.println(sb);
}
public static void add(int bit){
num |= (1<<bit);
// System.out.println(num);
}
public static void remove(int bit){
num &= ~(1<<bit);
}
public static void check(int bit){
if((num &(1<<bit))>0){
// System.out.println("1");
sb.append("1").append("\n");
}
else{
// System.out.println("0");
sb.append("0").append("\n");
}
}
public static void toggle(int bit){
num ^= (1<<bit);
}
public static void all(){
num = (1<<20) - 1;
}
public static void empty(){
num = 0;
}
}