Guest User

Untitled

a guest
Nov 25th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1.  
  2. Problem Statement
  3.     
  4. Select two numbers between 1 and 9998, inclusive, which have the same exact group of non-zero digits, but are not the same number. For example, you could use 1234 and 4321, or 91 and 901. Now, subtract the smaller of the two numbers from the larger. Finally, pick one of the non-zero digits in the result, and remove the digit from the number. If the resulting number is less than 100, prepend enough zeros so that it has 3 digits. It turns out, that given the remaining 3 digits, one can always determine the digit removed. (See examples for clarification)
  5. You will be given a string leftOver, which contains the three digits left over after the above algorithm is run. You must return the digit which was removed.
  6. Definition
  7.     
  8. Class:
  9. NumberGuesser
  10. Method:
  11. guess
  12. Parameters:
  13. string
  14. Returns:
  15. int
  16. Method signature:
  17. int guess(string leftOver)
  18. (be sure your method is public)
  19.     
  20.  
  21. Notes
  22. -
  23. Although it may not be obvious, there is only one answer for each input.
  24. -
  25. You can only remove a non-zero digit when running the algorithm.
  26. -
  27. HINT: work backwards from the input.
  28. Constraints
  29. -
  30. leftOver will consist of exactly 3 characters.
  31. -
  32. Each character of leftOver will be a digit '0'-'9'.
  33. -
  34. The input will be possible to acheive by performing the algorithm stated above.
  35. Examples
  36. 0)
  37.  
  38.     
  39. "087"
  40. Returns: 3
  41. Take the number 4321 and subtract 1234, you get 3087. Remove the 3, and the resulting digits are 087.
  42. 1)
  43.  
  44.     
  45. "099"
  46. Returns: 9
  47. One possible way to achieve this is by using the numbers 1000 and 1.
  48. 2)
  49.  
  50.     
  51. "191"
  52. Returns: 7
  53. 4525 - 2554 = 1971 also, you could get this with: 1900 - 109 = 1791 or 7900 - 709 = 7191
  54. 3)
  55.  
  56.     
  57. "689"
  58. Returns: 4
Add Comment
Please, Sign In to add comment