提交时间:2024-08-19 22:08:42
运行 ID: 168059
#include<bits/stdc++.h> using namespace std; long long f1(int K, const string &N) { long long decimalValue = 0; long long basePower = 1; for (int i = N.length() - 1; i >= 0; --i) { int digit; if (N[i] >= '0' && N[i] <= '9') { digit = N[i] - '0'; } else { digit = N[i] - 'A' + 10; } decimalValue += digit * basePower; basePower *= K; } return decimalValue; } string f2(int L, long long decimalValue) { if (decimalValue == 0) return "0"; string result; while (decimalValue > 0) { int remainder = decimalValue % L; if (remainder < 10) { result += (char)(remainder + '0'); } else { result += (char)(remainder - 10 + 'A'); } decimalValue /= L; } reverse(result.begin(), result.end()); return result; } int main() { int K, L; string N; while (cin >> K >> N >> L) { long long decimalValue = f1(K, N); string result = f2(L, decimalValue); cout << result << endl; } return 0; }