https://www.acmicpc.net/problem/11005
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String[] input = br.readLine().split(" ");
int n = Integer.valueOf(input[0]);
int b = Integer.valueOf(input[1]);
bw.write(Integer.toString(n,b).toUpperCase());
bw.flush();
}
}
라이브러리를 안쓰고 푸는법
import java.util.Scanner;
class Main
{
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int B = sc.nextInt();
String ans = "";
while (N > 0) {
int digit = N % B;
if (digit < 10) ans += digit;
else ans += (char)('A' + digit - 10);
N /= B;
}
System.out.println(new StringBuilder(ans).reverse());
}
}
유사문제
https://yunzae.tistory.com/318
'Problem Solving > 구현' 카테고리의 다른 글
BOJ3085 사탕 게임 (1) | 2024.01.30 |
---|---|
BOJ11068 회문인수 (1) | 2024.01.30 |
BOJ10448 유레카이론* (1) | 2024.01.30 |
BOJ3273 두 수의 합* (1) | 2024.01.29 |
BOJ10989 수 정렬하기3 (1) | 2024.01.29 |