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

建议使用的浏览器:

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

1790:Base Numbers

题目描述
Any integer number can be written as a sequence of digits. The most popular system is decimal, which uses ten digits (its base is 10). Besides, other systems with different bases can be used. For instance, the binary system (with the base of 2) is often used in relation to computers.

Generally, if we have a non-negative integer number n expressed as a sequence of digits
dk dk-1 ...d2 d1 d0

in the system with the base r (r > 1), then the value of the number is
n = dk*rk + dk-1*rk-1 + ... + d2*r2 + d1*r + d0.

Under any circumstances, each digit must be smaller than the base, 0 <= di < r for every i, 0 <= i <= k.
Some problems arise when we use bases greater than 10, because then we need more than 10 popular digits. A common solution is to use letters for ``digits'' greater than 9. Although this solution pushes limits a little further, it does not avoid the problem itself -- the set of letters is still very limited. Thus, higher bases could not be used.
Another solution is to write every digit separately as a number in the decimal system. For example, the hexadecimal number 1A8D (in usual notation) can be written as ``(1-10-8-13)16''. Please note that the number is always followed by the base value (even in the decimal system) to avoid misinterpretations. This number format is called a decimal-encoded notation in this text.
A number in the decimal-encoded notation is considered valid only if it contains no unnecessary zeros, i.e., additional leading zeros cannot appear in the base value or in any of the digits. Moreover, all digits must always be smaller than the base value. Thus, ``(1-0-0-0)7'', ``(4-7689)7690'', and ``(0)16'' are valid decimal-encoded numbers, on the other hand, ``(0-3-6)8'', ``(1-02-3)6'', ``(3-2-1)07'', and ``(9)6'' are invalid.
Due to some implementation reasons, ACM stores some data in valid decimal-encoded formats with various bases. Due to a software bug, a file containing a set of such numbers was damaged. All decimal digits has been preserved in the right order, but all of the dashes and parentheses were lost. Thus, each representation of a number was transformed to a code consisting of decimal digits only. Unfortunately, these codes are very ambiguous, most of them could represent many different numbers. For instance, ``1234'' could stand for ``(1-2-3)4'', ``(12)34'', ``(1-2)34'', or ``(1)234''. Your task is to determine the number of different representations that a code could stand for.
输入解释
The input file consists of several lines. Each line contains one code, i.e., the string consisting of decimal digits. The maximum length of any code is 35, the minimum length is 1. The last line of the input file contains a single hash character ("#").
输出解释
For each code, output a single line of text. If there is no valid representation of a number resulting in the given code, print a single line containing the text "The code CCC is invalid.". Otherwise, print the text "The code CCC can represent X numbers.". Replace CCC with the given code. Replace X with the total number of different representations in the decimal-encoded notation that would result in the given code when dashes and parentheses are removed. Note that the representations of numbers are considered different even if they result in the same value.
输入样例
1234
102
201
123456
#
输出样例
The code 1234 can represent 4 numbers.
The code 102 can represent 1 numbers.
The code 201 is invalid.
The code 123456 can represent 13 numbers.

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 CTU Open 2003

源链接: POJ-1790

最后修改于 2020-10-29T06:14:05+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 30000