提交时间:2023-08-21 23:16:45
运行 ID: 99092
#include <iostream> #include <string> using namespace std; int after[100]; string chars = "0123456789ABCDEF"; long long getNumber(string& S, long long K) { long long val = 0; long long W = 1; for (int i = S.size() - 1; i >= 0; i--) { if (S[i] >= 'A' && S[i] <= 'F') { val += ((S[i] - 'A') + 10) * W; } else { val += (S[i] - '0') * W; } W *= K; } return val; } int getAfterVal(long long VAL, long long L) { int len = 0; while(VAL != 0) { after[len++] = VAL % L; VAL /= L; } return len; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long K, L; string V; while(cin >> K) { cin >> V >> L; long long val = getNumber(V, K); int len = getAfterVal(val, L); for (int i = len - 1; i >= 0; i--) { cout << chars[after[i]]; } cout << "\n"; } return 0; }