본문 바로가기

자바(JAVA)/자료구조 & 알고리즘

백준 2745번 자바(JAVA)

백준 2745번 문제

 

 

백준 2745번 문제 자바 풀이

 

이 문제는 진법 변환 문제로 String 타입으로 받은 N 값을 B진수 값으로 바꾸는 문제이다.

 

Integer.parseInt(String s, int radix) 함수를 활용하면 쉽게 문제를 풀 수 있다.

 

 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		int idx = str.indexOf(" ");

		String N = str.substring(0, idx);

		int B = Integer.parseInt(str.substring(idx + 1, str.length()));

		br.close();

		System.out.println(Integer.parseInt(N, B));

	}
 }