Advertisement
SimeonTs

SUPyF2 Lists-Advanced-Lab - 01. Trains

Oct 9th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. """
  2. Lists Advanced - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1730#0
  4.  
  5. SUPyF2 Lists-Advanced-Lab - 01. Trains
  6.  
  7. Problem:
  8. You will receive how many wagons the train has. Create a list with that length with all zeros.
  9. Until you receive the command "End", you get some of the following commands:
  10. • add {people} -> adds the people in the last wagon
  11. • insert {index} {people} -> adds the people at the given wagon
  12. • leave {index} {people} -> removes the people from the wagon
  13. After you receive the "End" command print the train
  14.  
  15. Example:
  16.  
  17. Input:          Output:
  18. 3               [10, 0, 20]
  19. add 20
  20. insert 0 15
  21. leave 0 5
  22. End
  23.  
  24. 5               [16, 32, 100, 0, 105]
  25. add 10
  26. add 20
  27. insert 0 16
  28. insert 1 44
  29. leave 1 12
  30. insert 2 100
  31. insert 4 61
  32. leave 4 1
  33. add 15
  34. End
  35. """
  36. wagons_count = int(input())
  37. wagons_list = [0] * wagons_count
  38.  
  39. while True:
  40.     command = input().split()
  41.     if command[0] == "End":
  42.         break
  43.     elif command[0] == "add":
  44.         wagons_list[-1] += int(command[1])
  45.     elif command[0] == "insert":
  46.         wagons_list[int(command[1])] += int(command[2])
  47.     elif command[0] == "leave":
  48.         wagons_list[int(command[1])] -= int(command[2])
  49.  
  50. print(wagons_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement