提交时间:2024-08-19 21:33:25

运行 ID: 167972

#include<iostream> #include<iomanip> #include<algorithm> using namespace std; string change(string n,int from,int to){ int d = 0; for(char c : n){ d = d*from+(c>='0'&&c<='9' ? c-'0' : c-'A'+10); } if(d == 0){ return "0"; } string r; while(d){ int t = d%to; if(t < 10){ r.push_back('0'+t); }else{ r.push_back('A'+t-10); } d /= to; } reverse(r.begin(),r.end()); return r; } int main(){ int k,n,l; for(; cin>>k>>n>>l; cout<<change(to_string(n),k,l)<<'\n'); return 0; }