22117_ArithmeticwithMorse

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

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

Pro.ID

22117

Title

Arithmetic with Morse

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    Morse code is a method used to transmit text messages as a series of dots "." and dashes "-". For example, the letter "A" is represented with ".-" and the letter "B" with "-...". This code has been used for several years in the army and civil applications, but you are going to use it to do math.

    With this in mind, we assign values to dots and dashes, and to save space we use two additional characters. The following table shows the four allowed characters and their values.

    Character   |   Value  
    --------------|-----------
     .       |  1    
    -       |  5  
                        :       |  2      ( two times "
    ." )
                        =       |  10     ( two times "
    -" )

    A Morse number is a string that only contains the above four characters; its value is the sum of the values assigned to each individual character. As an example, the value of "=.-.." is 10+1+5+1+1 = 18. Notice that each Morse number represents a unique value, but there are values that can be represented with several Morse numbers. For instance, there are three Morse numbers with value 3: "...", ".:" and ":.".

    Well, numbers are ready. To form expressions we also need operators. We consider two arithmetic operators: "+" represents addition, while "*" represents multiplication. A Morse expression is a sequence of strings that interleaves Morse numbers and operators, that starts and ends with a Morse number, and contains at least one operator. Morse expressions can be evaluated by replacing each Morse number by its value, and then evaluating the obtained mathematical expression using the common operators precedence and associativity. For example, the value of the Morse expression "=.-.. + ... * :." is 18 + 3  3 = 18 + (3  3) = 27. Given a Morse expression, print its value.

    输入

    The rst line contains an integer N (1 ≤ N ≤ 4) representing the number of operators in the Morse expression. The second line contains 2N + 1 non-empty strings representing the Morse expression. The line interleaves Morse numbers and operators, being the rst and last strings Morse numbers. Each Morse number is at most 7 characters long, where each character is either ".", "-", ":" or "=". Each operator is either "+" or "*".

    输出

    Description

    Morse code is a method used to transmit text messages as a series of dots "." and dashes "-". For example, the letter "A" is represented with ".-" and the letter "B" with "-...". This code has been used for several years in the army and civil applications, but you are going to use it to do math.

    With this in mind, we assign values to dots and dashes, and to save space we use two additional characters. The following table shows the four allowed characters and their values.

    Character   |   Value  
    --------------|-----------
     .       |  1    
    -       |  5  
                        :       |  2      ( two times "
    ." )
                        =       |  10     ( two times "
    -" )

    A Morse number is a string that only contains the above four characters; its value is the sum of the values assigned to each individual character. As an example, the value of "=.-.." is 10+1+5+1+1 = 18. Notice that each Morse number represents a unique value, but there are values that can be represented with several Morse numbers. For instance, there are three Morse numbers with value 3: "...", ".:" and ":.".

    Well, numbers are ready. To form expressions we also need operators. We consider two arithmetic operators: "+" represents addition, while "*" represents multiplication. A Morse expression is a sequence of strings that interleaves Morse numbers and operators, that starts and ends with a Morse number, and contains at least one operator. Morse expressions can be evaluated by replacing each Morse number by its value, and then evaluating the obtained mathematical expression using the common operators precedence and associativity. For example, the value of the Morse expression "=.-.. + ... * :." is 18 + 3  3 = 18 + (3  3) = 27. Given a Morse expression, print its value.

    Input

    The rst line contains an integer N (1 ≤ N ≤ 4) representing the number of operators in the Morse expression. The second line contains 2N + 1 non-empty strings representing the Morse expression. The line interleaves Morse numbers and operators, being the rst and last strings Morse numbers. Each Morse number is at most 7 characters long, where each character is either ".", "-", ":" or "=". Each operator is either "+" or "*".

    Output

    Output a line with an integer representing the value of the Morse expression.

    Sample Input

    Sample #1
    2
    =.-.. + ... * :.


    Sample #2
    3
    - * - + - * -

    Sample Output

    Sample #1
    27

    Sample #2
    50

    Hint

    从10开始的测试数据缺少OUT文件

    Source

    样例输入

    Sample #1
    2
    =.-.. + ... * :.


    Sample #2
    3
    - * - + - * -

    样例输出

    Sample #1
    27

    Sample #2
    50

    提示

    从10开始的测试数据缺少OUT文件


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部