BOJ_S5_11723
π [S5_11723] μ§ν©
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static StringTokenizer st;
static int check_res;
static int num;
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[] arr = new int[21];
for(int i=0; i<M; i++){
st = new StringTokenizer(br.readLine(), " ");
switch (st.nextToken()){
case "add":
int num = Integer.parseInt(st.nextToken());
arr[num] = num ;
break;
case "remove":
arr[Integer.parseInt(st.nextToken())] = 0;
break;
case "check":
int num_2 = Integer.parseInt(st.nextToken());
if(arr[num_2]==num_2){
check_res = 1;
}
else{
check_res = 0;
}
sb.append(check_res).append("\n");
break;
case "toggle":
int temp = Integer.parseInt(st.nextToken());
if(arr[temp] == temp){
arr[temp] = 0;
}
else{
arr[temp] = temp;
}
break;
case "all":
for(int j=1; j<21; j++){
arr[j] = j;
}
break;
case "empty":
for(int j=1;j<21;j++){
arr[j]=0;
}
break;
}
}
System.out.println(sb);
}
}
π€ λμ μκ°
μ΄ λ¬Έμ λ μ΄λ»κ² 보면 κ°λ¨νμ§λ§ μκ° λ³΅μ‘λ λλ¬Έμ λ§μ μ¬λλ€μ΄ μ λ₯Ό λ¨Ήλ λ¬Έμ μ΄λ€.
λλ μ΄λ»κ² μ΄λ»κ² λ°°μ΄λ‘ λ§λ¬΄λ¦¬ νμ§λ§ λ¬Έμ μ μλλ λΉνΈλ§μ€νΉμ ν΅ν΄ λ¬Έμ λ₯Ό νΈλ κ²μ΄λ€.
κ·Έλ¬λ μμ§.. λΉνΈλ§μ€νΉμ λν μ΄ν΄κ° μ λλ‘ λμ΄ μμ§ μμμ λμ€μ 곡λΆλ₯Ό νκ³ λλ©΄ μ§νν΄λ³΄κ² λ€
κ·Έλ¬λ λͺ¨λ‘κ°λ μμΈλ§ κ°λ©΄ λλ€κ³ λ°°μ΄λ‘λ μ ν΄μ§ μκ°μ μΆ©μ‘±νμ¬ ν΄κ²°ν΄λλ€ ^^
λ°°μ΄μμμ ν¬μΈνΈλ StringBuilderμ StringTokenizer μλ€.