SimeonTs

SUPyF2 Lists-Advanced-Exercise - 04. Office Chairs

Oct 10th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. """
  2. Lists Advanced - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1731#3
  4.  
  5. SUPyF2 Lists-Advanced-Exercise - 04. Office Chairs
  6.  
  7. Problem:
  8. So you've found a meeting room - phew! You arrive there ready to present,
  9. and find that someone has taken one or more of the chairs!!
  10. You need to find some quick.... check all the other meeting rooms to see if all of the chairs are in use.
  11. You will be given a number n representing how many rooms there are.
  12. On the next n lines for each room you will get how many chairs there are and how many of them will be taken.
  13. The chairs will be represented by "X"s, then there will be a space " " and a number representing the taken places.
  14. Example: "XXXXX 4" (5 chairs and 1 of them is left free). Keep track of the free chairs, you will need them later.
  15. However if you get to a room where there are more people than chairs,
  16. print the following message: "{needed_chairs_in_room} more chairs needed in room {number_of_room}".
  17. If there is enough chairs in each room print: "Game On, {total_free_chairs} free chairs left"
  18.  
  19. Example
  20. Input               Output
  21. 4                   Game On, 4 free chairs left
  22. XXXX 4
  23. XX 1
  24. XXXXXX 3
  25. XXX 3
  26.  
  27. 3                   1 more chairs needed in room 2
  28. XXXXXXX 5           2 more chairs needed in room 3
  29. XXXX 5
  30. XXXXXX 8
  31. """
  32. rooms = int(input())
  33. free_chairs = 0
  34. game_on = True
  35.  
  36. for room in range(1, rooms + 1):
  37.     chairs, people = input().split()
  38.     chairs = len(chairs)
  39.     people = int(people)
  40.     if people > chairs:
  41.         game_on = False
  42.         print(f"{people - chairs} more chairs needed in room {room}")
  43.     elif chairs > people:
  44.         free_chairs += chairs - people
  45.  
  46. if game_on:
  47.     print(f"Game On, {free_chairs} free chairs left")
Add Comment
Please, Sign In to add comment