Base Conversion

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <cmath>
using namespace std;



int main() {
	freopen("input.txt", "rt", stdin);
	int a, b, m;
	int num[25];
	cin >> a >> b >> m;

	int sum = 0;
	for (int i = 0; i < m; i++) {
		cin >> num[i];
		sum = sum + num[i] * pow(a, m - i - 1);
	}
	
	stack<int> s;
	while (sum > 0) {
		int tmp = sum % b;
		s.push(tmp);
		sum /= b;
	}
	int sts = s.size();
	for (int i = 0; i < sts; i++) {
		printf("%d ", s.top());
		s.pop();
	}
	


	return 0;
}

좋은 웹페이지 즐겨찾기