728x90
문제
8진수가 주어졌을 때, 2진수로 변환하는 프로그램을 작성하시오.
입력
첫째 줄에 8진수가 주어진다. 주어지는 수의 길이는 333,334을 넘지 않는다.
출력
첫째 줄에 주어진 수를 2진수로 변환하여 출력한다. 수가 0인 경우를 제외하고는 반드시 1로 시작해야 한다.
코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
static String[] arr=new String[]{"0","1","10","11","100","101","110","111"};
static String[] brr=new String[] {"000","001","010","011","100","101","110","111"};
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader bs = new BufferedReader(new InputStreamReader(System.in));
String n = bs.readLine();
firstOctToBin(Integer.parseInt(n.substring(0,1)));
for(int i=1;i<n.length();i++) {
octToBin(Integer.parseInt(n.substring(i, i+1)));
}
}
private static void firstOctToBin(int n) {
System.out.print(arr[n]);
}
private static void octToBin(int n) {
System.out.print(brr[n]);
}
}
728x90
728x90
'Algorithm > Baekjoon' 카테고리의 다른 글
Baekjoon 2739 구구단 JAVA (0) | 2022.01.10 |
---|---|
Baekjoon 1267 핸드폰 요금 JAVA (0) | 2022.01.10 |
Baekjoon 1085 직사각형에서 탈출 JAVA (0) | 2022.01.10 |
Baekjoon 1009 분산처리 JAVA (0) | 2022.01.10 |
Baekjoon 2558 A+B - 2 JAVA (0) | 2022.01.10 |
댓글