当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6828:Little Rabbit's Equation

题目描述
Little Rabbit is interested in radix. In a positional numeral system, the radix is the number of unique digits, including the digit $0$, used to represent numbers. For example, for the decimal system (the most common system in use today) the radix is ten, because it uses the ten digits from $0$ to $9$. Generally, in a system with radix $b$ ($b > 1$), a string of digits $d_1 \dots d_n$ denotes the number $d_1b^{n-1} + d_2b^{n-2} + \dots + d_nb^0$, where $0 \le d_i < b$.

Little Rabbit casually writes down an equation. He wonders which radix this equation fits.
输入解释
The are several test cases. Each test case contains a string in a line, which represents the equation Little Rabbit writes down. The length of the string is at most $15$. The input is terminated by the end-of-file.

The equation's format: number, operator, number, $=$, number. There's no whitespace in the string.

Each number has at least $1$ digit, which may contain digital numbers $0$ to $9$ or uppercase letters $A$ to $F$ (which represent decimal $10$ to $15$). The number is guaranteed to be a non-negative integer, which means it doesn't contain the radix point or negative sign. But the number may contain leading zeros.

The operator refers to one of $+$, $-$, $*$, or $/$. It is guaranteed that the number after $/$ will not be equal to $0$. Please note that the division here is not integer division, so $7/2=3$ is not correct.
输出解释
For each test case, output an integer $r$ ($2 \le r \le 16$) in a line, which means the equation is correct in the system with radix $r$. If there are multiple answers, output the minimum one. If there is no answer between $2$ and $16$, output $-1$.
输入样例
1+1=10
18-9=9
AA*AA=70E4
7/2=3
输出样例
2
10
16
-1
来自杭电HDUOJ的附加信息
Recommend IceyWang

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6828

最后修改于 2020-10-25T23:34:44+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)