티스토리 뷰
문제링크 : https://www.acmicpc.net/problem/11576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int A, B, m;
int arr[26];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> A >> B >> m;
for(int i=0; i<m; i++) cin >> arr[i];
int idx = 0, tmp = 0;
for(int i=m-1; i>=0; i--)
{
tmp += arr[idx]*pow(A, i);
idx++;
}
vector<int>v;
while(tmp >= B)
{
v.push_back(tmp%B); //몫 넣기
tmp /=B;
if(tmp < B) v.push_back(tmp); //나머지 넣기
}
for(int i = v.size()-1; i>=0; i--) cout << v[i] << " ";
return 0;
}
처음 A진법을 10진수로 변환시키고, 다시 입력받은 B진법으로 계산하여 출력해주면 된다.
'백준 > 실버' 카테고리의 다른 글
[백준 17087번] 숨바꼭질 6 (C++) (0) | 2025.04.13 |
---|---|
[백준 2089번] -2진수 (C++) (0) | 2025.04.12 |
[백준 10973번] 이전 순열 (C++) (0) | 2025.04.11 |
[백준 1850번] 최대공약수 (C++) (0) | 2025.04.10 |
[백준 4134번] 다음 소수 (C++) (0) | 2025.04.09 |