提交时间:2023-08-21 16:19:57
运行 ID: 99019
#include <bits/stdc++.h> using namespace std; int g(char c) { if ('0' <= c && c <= '9') return c - '0'; else return c - 'A' + 10; } char z(int i) { if (i < 10) return '0' + i; else return 'A' + (i - 10); } int main() { int k, l; string n; while(cin >> k >> n >> l) { int s = 0, m=1; for (int i = n.size() - 1; i >= 0; i--) { s += g(n[i]) * m; m *= k; } char j[10]; int cnt=0; while (s) { j[cnt] = z(s % l); cnt++; s /= l; } for (int i = cnt-1; i >= 0; i--) { cout << j[i]; } cout << endl; } }