21542_ToothpickArithmetic

2022-5-16 18:19| 发布者: Hocassian| 查看: 23| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505409057300-Problem List-采集的数据-后羿采集器.html

Pro.ID

21542

Title

Toothpick Arithmetic

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21542

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    A toothpick expression uses toothpicks to represent a positive integer. The expression consists of operands and operators.

    Each operand consists of one or more vertical toothpicks ("|"); the value of the operand is the number of toothpicks.

    The operators that can appear in an expression are addition and multiplication. The addition operator is the plus sign ("+"), which consists of one vertical and one horizontal toothpick. The multiplication operator is the letter "x", which also consists of two toothpicks. Multiplication has precedence over addition.

    The expression must begin with an operand. Thereafter, operators and operands alternate. Finally, the expression must end with an operand. Given a positive integer, your program must represent it as a toothpick expression, using the smallest number of toothpicks.

    输入

    The input file will consist of one or more lines; each line will contain data for one instance of the problem. More specifically, each line will contain one positive integer, not exceeding 5000.

    输出

    Description

    A toothpick expression uses toothpicks to represent a positive integer. The expression consists of operands and operators.

    Each operand consists of one or more vertical toothpicks ("|"); the value of the operand is the number of toothpicks.

    The operators that can appear in an expression are addition and multiplication. The addition operator is the plus sign ("+"), which consists of one vertical and one horizontal toothpick. The multiplication operator is the letter "x", which also consists of two toothpicks. Multiplication has precedence over addition.

    The expression must begin with an operand. Thereafter, operators and operands alternate. Finally, the expression must end with an operand. Given a positive integer, your program must represent it as a toothpick expression, using the smallest number of toothpicks.

    Input

    The input file will consist of one or more lines; each line will contain data for one instance of the problem. More specifically, each line will contain one positive integer, not exceeding 5000.

    Output

    Each line of input will give rise to one line of output, consisting of: the number of toothpicks used in the expression, the expression, and the given integer from the input, formatted as shown in the sample output. The word "toothpicks" (even if the answer is 1) will be preceded by one blank space and followed by a colon and one blank space. An equal sign (but no blank spaces) will separate the expression from the given number. The expression should not contain any spaces.

    If there are multiple expressions which use the smallest number of toothpicks, any such expression is acceptable.

    Sample Input

    35
    37
    53

    Sample Output

    14 toothpicks: |||||||x|||||=35
    17 toothpicks: ||||||x||||||+|=37
    21 toothpicks: |||||x|||||x||+|||=53

    Source

    样例输入

    35
    37
    53

    样例输出

    14 toothpicks: |||||||x|||||=35
    17 toothpicks: ||||||x||||||+|=37
    21 toothpicks: |||||x|||||x||+|||=53

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部