728x90
▶ 11005번 문제 - 진법변환2
- 입력된 두 숫자 N, B
- 숫자 N을 B진법 형태로 변환하는 문제 ( N은 10억보다 작거나 같음(Long형), B범위 : 2<= B <=36 )
▶ 풀이방법
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Stack<Character> stack = new Stack<>();
StringTokenizer st = new StringTokenizer(br.readLine());
long a = Long.parseLong(st.nextToken());
long b = Long.parseLong(st.nextToken());
while(a > 0) {
stack.push((char)(ck(a, b)));
a /= b;
}
while(!stack.isEmpty()) bw.write(stack.pop());
bw.flush();
bw.close();
br.close();
}
private static long ck(long a, long b) {
return a%b > 9 ? (a%b + 55) : (a%b + 48);
}
}
728x90