๋นํธ๋ง์คํน์ผ๋ก ํธ๋ ๋ฌธ์ ์ด๋ค.
ํ์ด
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/*
* M์ ์ด์ง์ ํํ์ ๋ง์ง๋ง N๋นํธ๊ฐ ๋ชจ๋ 1๋ก ์ผ์ ธ ์๋์ง ์๋์ง ํ๋ณ
*/
public class Solution {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int mask = (1 << N) - 1; //๋ง์ง๋ง N๋นํธ๊ฐ 1๋ก ์ผ์ง ex) 4 : 10000 - 1 = 01111
int result = M & mask; // ex) 47 & 1111 = 101111 & 001111 = 001111
String answer = (mask == result) ? "ON" : "OFF";
System.out.println("#" + t + " " + answer);
}
}
}
๊ฒฐ๊ณผ
'Algorithm > SWEA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
SWEA - ์๋ก์ด ๋ถ๋ฉด์ฆ ์น๋ฃ๋ฒ (0) | 2023.02.05 |
---|---|
SWEA - 1249๋ฒ ๋ณด๊ธ๋ก (0) | 2022.09.30 |
SWEA 5215๋ฒ - ํ๋ฒ๊ฑฐ ๋ค์ด์ดํธ (0) | 2022.08.11 |
SWEA 6808๋ฒ - ๊ท์์ด์ ์ธ์์ด์ ์นด๋๊ฒ์ (0) | 2022.08.09 |
SWEA 9229๋ฒ - ํ๋น์ด์ Spot Mart (0) | 2022.08.08 |