mug_color.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/python
  2. # Memory Limit:1024 MB
  3. # Time Limit: 5 s
  4. # Mug Color (100 points)
  5. # Introduction
  6. # Jay S. has got himself in trouble! He had borrowed a friend's coffee mug and somehow lost it. As his
  7. # friend will be extremely angry when he finds out about it, Jay has decided to buy his friend a replacement
  8. # mug to try to control the damage.
  9. # Unfortunately, Jay does not remember the color of the mug he had borrowed. He only knows that the
  10. # color was one of White, Black, Blue, Red or Yellow.
  11. # Jay goes around his office asking his colleagues if they are able to recall the color but his friends don't
  12. # seem to remember the color of the mug either. What they do know is what color the mug definitely was
  13. # not.
  14. # Based on this information, help Jay figure out what the color of the mug was.
  15. # Input Specifications
  16. # Your program will take
  17. # An input N (1 ≤ N ≤ 1,000,000) which denotes the number of people Jay questions regarding the
  18. # mug.
  19. # This will be followed by N strings S[1],S[2]...S[N] where S[I] denotes the response of person I to
  20. # Jay's question which is what color the mug definitely was not. S[I] will also be only one of the 5
  21. # colors namely White, Black, Blue, Red or Yellow.
  22. # Output Specifications
  23. # Based on the input, print out the color of the mug. The color of the mug can only be one of the 5 colors
  24. # namely White, Black, Blue, Red or Yellow.
  25. # You can safely assume that there always exists only one unique color that the mug can have.
  26. # Sample Input/Output
  27. # Input
  28. # 4
  29. # White
  30. # Yellow
  31. # Blue
  32. # Black
  33. # Output
  34. # Red
  35. # Explanation
  36. # Jay's colleagues have mentioned every color except Red so the mug is Red in color
  37. # Input
  38. # 9
  39. # White
  40. # Yellow
  41. # Blue
  42. # Black
  43. # Black
  44. # White
  45. # Yellow
  46. # Blue
  47. # Black
  48. # Output
  49. # Red
  50. # Explanation
  51. # Similar to the above case, the only color not mentioned is Red
  52. from __future__ import print_function
  53. import sys
  54. white = True
  55. black = True
  56. blue = True
  57. red = True
  58. yellow = True
  59. data = sys.stdin.readlines()
  60. for line in data :
  61. if (line == "White\n"):
  62. white = False
  63. elif (line == "Black\n"):
  64. black = False
  65. elif (line == "Blue\n"):
  66. blue = False
  67. elif (line == "Red\n"):
  68. red = False
  69. elif (line == "Yellow\n"):
  70. yellow = False
  71. if (white == True):
  72. print ("White")
  73. elif (black == True):
  74. print ("Black")
  75. elif (blue == True):
  76. print ("Blue")
  77. elif (red == True):
  78. print ("Red")
  79. elif (yellow == True):
  80. print ("Yellow")