# 진법 변환 2
문제
10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오.
10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를 사용한다.
A: 10, B: 11, ..., F: 15, ..., Y: 34, Z: 35
입력
첫째 줄에 N과 B가 주어진다. (2 ≤ B ≤ 36) N은 10억보다 작거나 같은 자연수이다.
출력
첫째 줄에 10진법 수 N을 B진법으로 출력한다.
예제 입력 1
60466175 36
예제 출력 1
ZZZZZ
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N, B;
cin >> N >> B;
string Result;
int remainder = N;
while (true)
{
int Num = remainder % B;
if (Num < 10) // 숫자
Result += to_string(Num);
else // 알파벳
Result += (char)(Num + 55);
remainder /= B;
if (remainder == 0)
break;
}
reverse(Result.begin(), Result.end());
cout << Result << "\n";
return 0;
}
'CodingTest > Baekjoon' 카테고리의 다른 글
[Baekjoon] 11653번 소인수분해 (0) | 2025.01.15 |
---|---|
[Baekjoon] 2903번 중앙 이동 알고리즘 (1) | 2025.01.14 |
[Baekjoon] 2745번 진법 변환 (1) | 2025.01.14 |
[Baekjoon] 10870번 피보나치 수 5 (0) | 2025.01.12 |
[Baekjoon] 2559번 수열 (0) | 2025.01.12 |