Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
167921 | C班詹皓杰 | 确定进制 | C++ | 解答错误 | 0 | 1 MS | 252 KB | 1176 | 2024-08-19 20:45:57 |
#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; } } cout<<0; return 0; }