Huawei OD computer test-Mars Computing 2 (Java & JS & Python & C)

Question description

It is known that the operators used by Martians are # and $, and their equivalent formulas to those on Earth are as follows:

  • x#y = 4*x+3*y+2
  • x$y = 2*x+y+3
  1. where x, y are unsigned integers
  2. Earthling formulas are calculated according to C language rules
  3. In the Martian formula, # has a higher priority than $, and the same operators are calculated from left to right.

There is a string message from Martians. Please translate it and calculate the result.

Enter description

Martian string expression (without carriage return and line feed at the end)

Description of the input string: The string is a calculation expression consisting only of unsigned integers and operators (#, $). For example:

123#4$5#67$78

  1. The use case ensures that there are no separators between operands and operators in the string.  
  2. The use case ensures that the operand value range is a 32-bit unsigned integer.  
  3. Ensure that input and calculation results will not cause integer overflow.  
  4. Ensure that the input string is a legal evaluation message, for example: 123#4$5#67$78  
  5. It is guaranteed that illegal evaluation messages will not appear, such as strings like this:  

    #4$5 //Missing operand  

    4$5# //Missing operand  

    4#$5 //Missing operand  

    4

Guess you like

Origin blog.csdn.net/qfc_128220/article/details/135398703