Loading Now

findMissingDigit

Jack is a Math teacher, he had his students done the final exam. And now it’s time for him to score students’ assignments. But the trouble comes with one of his student – Tom. Tom is very good at math, but He has very bad handwriting. And in his assignment, there are some equation Jack can not find out which digit did Tom write. So he ask you for help. Now, your mission is to help the poor Math teacher to find out the equation had been written by Tom
The form of equation:
[number][operator][number]=[number]
Where:
– Operator is +, - or *
– Number is the integers in the range from -999999 to 999999
– There are some characters “X” in Tom’s assignment that present the missing digits (note that all the Xs in one equation present the same number and it won’t be one of the other 
given digits in the expression)

If there are more than one possible digit, choose the smallest one.

Example: 

  • For input expression = "1+1=X". The output should be:  findMissingDigit(n) = 2
    Because 1+1=2
  • For input expression = "X*11=XX". The output should be:  findMissingDigit(n) = 2
    Because 2*11=22. Note that in this case 1 is not the right answer because it’s already in the expression. And 2 is the smallest digit that satisfies the expression.

Input/Output:

  • [Execution time limit] 0.5s (C++), 3s (Java , C#), 4s (Python,JavaScript)

  • [Input] string expression
    A string represents the expression Tom wrote in form:
    [number][operator][number]=[number]
    −999999 ≤ [number] 999999

  • [Output] integer

    The missing digit.

Post Comment

Contact