提交时间:2024-07-22 15:57:12

运行 ID: 158206

#include<bits/stdc++.h> using namespace std; int k, l, len; string n; int k_10(string x){ int kk = 1, sum = 0; for(int i = len-1; i >= 0; i--){ if(x[i] >= 'A' && x[i] <= 'Z'){ sum += (x[i]-'A'+10)*kk; }else sum += (x[i]-'0')*kk; kk *= k; } return sum; } string s_l(int x){ string s = ""; while(x != 0){ if(x%l >= 10){ s = char(x%l-10+'A')+s; }else s = char(x%l+'0')+s; x /= l; } return s; } int main(){ while(cin >> k >> n >> l){ len = n.size(); if(k == l){ cout << n << endl; continue; } int num = k_10(n); cout << s_l(num) << endl; } return 0; }