提交时间:2024-08-20 19:35:25

运行 ID: 169882

#include <iostream> #include <algorithm> #include <string> #include <cmath> using namespace std; long long toTen(string str, int n) { long long a=0; for (int i = 0; i < str.size(); i++){ a*=n; if(str[i]>='0'&&str[i]<='9') a+=str[i]-'0'; if(str[i]>='a'&&str[i]<='z') a+=str[i]-'a'+10; if(str[i]>='A'&&str[i]<='Z') a+=str[i]-'A'+10; } return a; } string toJZ(long long data, int n){ char str[100]; int i=0; while(data!=0){ int d = data%n; if(d>9){ str[i]='a'+d-10; } else { str[i]='0'+d; } data/=n; i++; } if(i==0){ str[0]='0'; i++; } str[i]=0; string s(str); reverse(s.begin(), s.end()); return s; } int maX(string str) { int max=2; for (int i = 0; i < str.size(); i++){ if(str[i]>='2'&&str[i]<='9'&&str[i]-'0'>max) max=str[i]-'0'; if(str[i]>='a'&&str[i]<='z'&&str[i]-'a'>max) max=str[i]-'a'; if(str[i]>='A'&&str[i]<='Z'&&str[i]-'A'>max) max=str[i]-'A'; } return max+1; } int main() { string str,str1,str2; long long a=0,b=0,c=0; cin>>str>>str1>>str2; int i=max(maX(str),max(maX(str1),maX(str2))); while (i<=16){ a=toTen(str,i); b=toTen(str1,i); c=toTen(str2,i); if(a*b==c){ cout<<i<<endl; return 0; } i++; } cout<<0<<endl; return 0; }