编程介的小学生 2019-09-14 02:48 采纳率: 20.5%
浏览 195

Base Numbers 可以代表几个数字的问题

Description

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.
Input

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 ("#").
Output

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.
Sample Input

1234
102
201
123456
#
Sample Output

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)