문제링크
https://www.acmicpc.net/problem/11723
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine());
int T = Integer.parseInt(st.nextToken());
int result = 0;
for(int t=0;t<T;t++) {
st = new StringTokenizer(br.readLine());
String str = st.nextToken();
int n;
switch (str) {
case "add":
n = Integer.parseInt(st.nextToken());
result|=(1<<n);
break;
case "remove":
n = Integer.parseInt(st.nextToken());
result &=~(1<<n);
break;
case "check":
n = Integer.parseInt(st.nextToken());
if((result&(1<<n)) !=0)
bw.write("1\n");
else
bw.write("0\n");
break;
case "toggle":
n = Integer.parseInt(st.nextToken());
result ^=(1<<n);
break;
case "all":
result = (1<<21)-1;
break;
case "empty":
result = 0;
break;
default:
break;
}
}
bw.flush();
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[JAVA]백준_10972_다음순열 (0) | 2021.02.16 |
---|---|
[JAVA]백준_10026_적록색약 (0) | 2021.02.15 |
[JAVA]백준_3040_백설공주와 일곱난쟁이 (0) | 2021.02.15 |
[JAVA]백준_11559_뿌요뿌요 (0) | 2021.02.15 |
[JAVA]백준_1697_숨바꼭질 (0) | 2021.02.14 |