240415 집합

Jongleee·2024년 4월 15일
0

TIL

목록 보기
547/737
public static void main(String[] args) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringBuilder sb = new StringBuilder();

	int M = Integer.parseInt(br.readLine());

	int s = 0;
	for (int i = 0; i < M; i++) {
		StringTokenizer st = new StringTokenizer(br.readLine());
		String command = st.nextToken();

		switch (command) {
			case "all":
				s = (1 << 21) - 1;
				break;
			case "empty":
				s = 0;
				break;
			default:
				int x = Integer.parseInt(st.nextToken());
				switch (command) {
					case "add":
						s |= (1 << x);
						break;
					case "remove":
						s &= ~(1 << x);
						break;
					case "check":
						sb.append((s & (1 << x)) != 0 ? 1 : 0).append('\n');
						break;
					case "toggle":
						s ^= (1 << x);
						break;
					default:
						break;
				}
		}
	}

	System.out.println(sb);
}

출처:https://www.acmicpc.net/problem/11723

0개의 댓글