提交时间:2023-08-21 16:22:25
运行 ID: 99025
#include <bits/stdc++.h> using namespace std; int change(char c) { if('0'<= c && c <= '9')return c-'0'; else if('A' <= c && c <= 'Z')return c-'A'+10; } int changee(string s, int k) { int tmp,cnt; tmp = 0; cnt = 1; for(int i = s.length()-1; i >= 0; i--) { tmp += cnt*change(s[i]); cnt*=k; } return tmp; } signed main() { string a,b,c; cin >> a >> b >> c; //changee(s,k)k进制s转换为10进制 int B; int tmp1,tmp2,tmp3; int maxn = -0x3f3f3f3f; for(int i = 0; i < a.size(); i++) { maxn = max(maxn,change(a[i])); } for(int i = 0; i < b.size(); i++) { maxn = max(maxn,change(b[i])); } for(int i = 0; i < c.size(); i++) { maxn = max(maxn,change(c[i])); } for(B = maxn+1; B <= 16; B++) { tmp1 = changee(a,B); tmp2 = changee(b,B); tmp3 = changee(c,B); if(tmp1 * tmp2 == tmp3) { cout << B << endl; exit(0); } } return 0; }