Updated:

1. 문제 링크

https://www.acmicpc.net/problem/11005

2. 사용 알고리즘

수학

3. 풀이

N이 0이 아닐 때까지 B로 나누며 나머지를 구하고, 구한 나머지의 역순으로 출력

4. 소스 코드

4-1. C++

https://github.com/dev-aiden/problem-solving/blob/main/boj/11005.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    ios_base::sync_with_stdio(false);
    int n, b; cin >> n >> b;
    string ans;
    while (n != 0) {
        int temp = n % b;
        if (temp < 10) ans += (temp + 48);
        else ans += (temp + 55);
        n /= b;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}

4-2. JAVA

https://github.com/dev-aiden/problem-solving/blob/main/boj/11005.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        StringBuilder ans = new StringBuilder();
        while (n != 0) {
            int temp = n % b;
            if (temp < 10) ans.append((char)(temp + 48));
            else ans.append((char)(temp + 55));
            n /= b;
        }
        ans.reverse();
        System.out.println(ans);
    }
}

Updated:

Leave a comment