진법 변환을 반대로 실행한다.
60466175를 36진법으로 나타낼 경우
60466175를 36으로 나눈 나머지를 기록하고
몫은 다시 36르노 나눈다.
나머지를 이어놓은 것이 36진법으로 나타냈을 때이다.
진법 변환 문제와 비슷하게 풀이를 진행하면 된다.
나머지와 몫을 잘 생각해보자.
//백준 11005, 진법 변환 2
#include <iostream>
#include <unordered_map>
#include <deque>
std::unordered_map<int, char> map;
int main(){
for(int i{0}; i <= 9; ++i)
map[i] = i + '0';
for(int i{10}; i<=36; ++i)
map[i] = 'A' + (i-10);
int N, B;
std::cin >> N >> B;
std::deque<char> d;
while(N >= B){
int num = N % B;
auto it = map.find(num);
d.push_front(it->second);
N /= B;
}
auto it = map.find(N);
d.push_front(it->second);
for(auto c : d) std::cout << c;
return 0;
}