提交时间:2024-08-19 20:50:19

运行 ID: 167930

#include <bits/stdc++.h> #include <cstring> using namespace std; string d = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int main() { int k, l; string s; while (cin >> k >> s >> l) { int p = 1; reverse(s.begin(), s.end()); int ans = 0; for (int i = 0; i < s.size(); i++) { if (s[i] >= '0' && s[i] <= '9') ans += p * (s[i] - 48); else ans += p * (s[i] - 55); p *= k; } string sum = ""; while (ans != 0) { sum += d[ans % l]; ans /= l; } for (int i = sum.length() - 1; i >= 0; i--) cout << sum[i]; cout << endl; } return 0; }