Advertisement
SimeonTs

SUPyF Lists - Extra 03. Camel's Back

Jun 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. """
  2. Lists
  3. Check your answer: https://judge.softuni.bg/Contests/Practice/Index/425#2
  4.  
  5. 03. Camel's Back
  6.  
  7. Problem:
  8. The city is breaking down on a camel back. You will receive a sequence of N integers, (space-separated),
  9. which will represent the buildings in the city.  You will then receive an integer M, indicating the camel back's size.
  10. The camel back is a linear structure standing below the city, in such a way that it has an equal amount of buildings
  11. to its left and right. The idea is, if every round – one building falls from the left side of the city, and one from
  12. the right side, how many rounds will it take for the city to stop breaking down?
  13. As output you must print how many rounds it took before the city stopped breaking down as “{rounds} rounds”.
  14. On the next line, print what’s left of the city (space-separated). Format: “remaining: {buildings (space-separated)}”
  15. If no buildings have fallen, print “already stable: {buildings (space-separated)}”
  16. Example: city with 9 elements; Camel back size: 5
  17. """
  18.  
  19. nums = [int(item) for item in input().split(" ")]
  20. m = int(input())
  21.  
  22. count_rounds = 0
  23.  
  24. while len(nums) != m:
  25.     nums.pop(0)
  26.     nums.pop(len(nums) - 1)
  27.     count_rounds += 1
  28.  
  29. if count_rounds == 0:
  30.     print(f"already stable: ", end="")
  31.     for num in nums:
  32.         print(num, end=" ")
  33.     print()
  34. else:
  35.     print(f"{count_rounds} rounds")
  36.     print(f"remaining: ", end="")
  37.     for num in nums:
  38.         print(num, end=" ")
  39.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement