슈콩

[SWEA] 이진수 표현 본문

Algorithms/SWEA

[SWEA] 이진수 표현

shukong 2025. 11. 15. 18:20

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXRSXf_a9qsDFAXS

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			String result = Integer.toBinaryString(m);
			boolean check = true;
			if(result.length()<n) check = false;
			else {
				for(int i=0;i<n;i++) {
					if(result.charAt(result.length()-1-i)!='1') check = false;
				}
			}
			if(!check) System.out.println("#"+tc+" OFF");
			else System.out.println("#"+tc+" ON");
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 영준이의 카드 카운팅  (0) 2025.11.15
[SWEA] 민정이와 광직이의 알파벳 공부  (0) 2025.11.15
[SWEA] 체스판 위의 룩 배치  (0) 2025.11.15
[SWEA] 무한 문자열  (0) 2025.11.15
[SWEA] 팰린드롬 문제  (0) 2025.11.15