문제 : https://www.acmicpc.net/problem/11576
[ 알고리즘풀이 ]
A진법으로 표현한 수를 10진법으로 돌리고, 다시 그 수를 B진법으로 표현하면 된다.
#include<iostream>
#include<vector>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int A, B, M, list[25] = {};
cin >> A >> B >> M;
for (int i = 0; i < M; i++)
cin >> list[i];
// A진법 수를 10진법으로
int temp = 0, mul = 1;
for (int i = 0; i < M; i++) {
temp += mul * list[M - 1 - i];
mul *= A;
}
// 10진법으로 표현한 수를 B진법으로
vector<int> ans;
while (temp) {
ans.push_back(temp % B);
temp /= B;
}
for (int i = 0; i < ans.size(); i++)
cout << ans[ans.size() - 1 - i] << ' ';
return 0;
}
'Problem Solving > BOJ' 카테고리의 다른 글
[BOJ] 15683 : 드래곤 커브 - travelbeeee (0) | 2020.02.26 |
---|---|
[BOJ] 13305 : 주유소 - travelbeeee (0) | 2020.02.25 |
[BOJ] 15992 : 1, 2, 3 더하기 7 - travelbeeee (0) | 2020.02.24 |
[BOJ] 15991 : 1, 2, 3 더하기 6 - travelbeeee (0) | 2020.02.24 |
[BOJ] 15990 : 1, 2, 3 더하기 5 - travelbeeee (0) | 2020.02.24 |