Home BOJ. Set (11723)
Post
Cancel

BOJ. Set (11723)

[Link] https://www.acmicpc.net/problem/11723


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
import java.util.*;
import java.io.*;

public class Main {
	static BufferedReader br;
	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int m = toi(br.readLine());
		String[] line;
		int bits = 0;
		for(int i = 0; i < m; i++) {
			line = getLine();
			if(line[0].equals("add")) {
				int x = toi(line[1]) - 1;
				bits = bits | 1 << x;
			} else if(line[0].equals("remove")) {
				int x = toi(line[1]) - 1;
				bits &= ~(1 << x);
			} else if(line[0].equals("check")) {
				int x = toi(line[1]) - 1;
				sb.append((bits &  1 << x) == 0 ? 0 : 1).append("\n");
			} else if(line[0].equals("toggle")) {
				int x = toi(line[1]) - 1;
				bits = bits ^ 1 << x;
			} else if(line[0].equals("all")) {
				bits = (1 << 20) - 1;
			} else bits = 0;
		}
		print(sb);
	}

	static int toi(String s) { return Integer.parseInt(s); }
	static String[] getLine() throws IOException { return br.readLine().split(" "); }
	static int[] getArr() throws IOException { return Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); }
	static <T> void print(T s) { System.out.print(s); }
	static <T> void println(T s) { System.out.println(s); }
}
This post is licensed under CC BY 4.0 by the author.