提交时间:2024-08-19 22:13:17

运行 ID: 168075

#include <iostream> #include <string> #include <algorithm> using namespace std; int tuer(const string &num, int base) { int result = 0; for (char c : num) { int digit; if (c >= '0' && c <= '9') { digit = c - '0'; } else { digit = c - 'A' + 10; } result = result * base + digit; } return result; } int main() { string p, q, r; cin >> p >> q >> r; char maxx = max({*max_element(p.begin(), p.end()), *max_element(q.begin(), q.end()), *max_element(r.begin(), r.end())}); int maxDigit = (maxx >= '0' && maxx <= '9') ? (maxx - '0') : (maxx - 'A' + 10); int minn = maxDigit + 1; int ans = 0; for (int base = minn; base <= 16; base++) { int pDec = tuer(p, base); int qDec = tuer(q, base); int rDec = tuer(r, base); if (pDec * qDec == rDec) { ans = base; break; } } cout << ans; return 0; }