Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
167945 C班詹皓杰 确定进制 C++ 解答错误 25 1 MS 256 KB 1604 2024-08-19 21:04:23

Tests(1/4):


#include<iostream> #include<cctype> #include<sstream> #include<iomanip> #include<string> using namespace std; string change(int decimal,int base){ stringstream ss; string result = ""; int remainder; if(decimal == 0){ return "0"; } while(decimal > 0){ remainder = decimal % base; if(remainder < 10){ ss<<remainder; }else{ ss<<static_cast<char>('A'+remainder-10); } decimal /= base; } string temp; ss>>temp; for(int i = temp.length()-1; i >= 0; --i){ result += temp[i]; } return result; } int change(string s,int from_base,int to_base){ 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,10); y = change(b,i,10); z = x*y; if(change(z,i) == c){ cout<<i; return 0; } } cout<<0; return 0; }


测评信息: