提交时间:2023-08-21 16:15:19
运行 ID: 99011
#include <bits/stdc++.h> //#define int long long using namespace std; string n; int l,k,tmp,cnt; vector<int>res; int change(char c) { if('0'<= c && c <= '9')return c-'0'; else if('A' <= c && c <= 'Z')return c-'A'+10; } char change2(int p) { if(p <= 9) { return p+'0'; } else { return (char)(p-10+'A'); } } signed main() { while(cin >> k >> n >> l) { res.clear(); tmp = 0; cnt = 1; for(int i = n.length()-1; i >= 0; i--) { tmp += cnt*change(n[i]); cnt*=k; } //cout << tmp << endl; while(tmp>0) { int tttmp = tmp%l; res.push_back(tttmp); tmp/=l; } for(int i = res.size()-1; i >= 0; i--) { cout << change2(res[i]); } cout << endl; } return 0; }