提交时间:2023-08-21 16:23:53
运行 ID: 99032
#include <iostream> #include <algorithm> using namespace std; int i; long long N_T(string n, int k) { long long num = 0; int l = n.size(); for (i = 0; i < l; i++) { if (n[i] >= '0' && n[i] <= '9') { num = num * k + (n[i] - '0'); } else { num = num * k + (n[i] - 'A' + 10); } } return num; } string T_M(long long n, int k) { string num1 = "", t = "0123456789ABCDEF"; while (n != 0) { num1 += t[n % k]; n /= k; } reverse(num1.begin(), num1.end()); return num1; } int main() { string n; int k, k1; while(cin>>k>>n>>k1){ cout << T_M(N_T(n, k), k1)<<endl; } return 0; }