提交时间:2024-08-19 20:44:40

运行 ID: 167918

#include<iostream> #include<cctype> #include<sstream> #include<iomanip> #include<string> using namespace std; string change(int n,int base){ stringstream ss; ss<<setbase(base)<<n; return ss.str(); } int change(string s,int from_base,int to_base=10){ int t; stringstream ss; ss<<setbase(from_base)<<s; ss>>setbase(to_base)>>t; return t; } template<typename Ta,typename Tb> Tb change(const Ta& a){ Tb b; stringstream stream; stream<<a; stream>>b; return b; } char find_biggest(string s){ char mx = 0; for(char c : s){ mx = max(c,mx); } return mx; } int lowest_base(char biggest){ if(isdigit(biggest)){ return biggest-'0'+1; }else{ return biggest-'A'+11; } } int main(){ int lb = 2; string a,b,c; int x,y,z; cin>>a>>b>>c; lb = lowest_base(max(find_biggest(a),max(find_biggest(b),find_biggest(c)))); for(int i = lb; i <= 16; i++){ x = change(a,i); y = change(b,i); z = x*y; if(change(z,i) == c){ cout<<i; break; } } return 0; }