Advertisement
SimeonTs

SUPyF Dictionaries Exercises - 02. Travel Company

Jun 24th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. """
  2. Dictionaries - Exercises
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/1088#1
  4.  
  5. SUPyF Dictionaries Exercises - 02. Travel Company
  6.  
  7. Problem:
  8. Write a program, which categorizes information about a travel company.
  9. Companies have various vehicles planned for different cities. Every city has prepared several types of vehicles.
  10. Each vehicle type has a different capacity.
  11. Until you receive the command “ready”, you will receive all the cities the company offers holiday packages for,
  12. and their respective vehicle types + capacities in the format:
  13. - “{city}:{type}-{capacity},{type}-{capacity}…”
  14. An example city with its transportation options would look like this:
  15. - “Athens:bus-40,airplane-300,train-150”
  16. If a city is entered a second time, add all transport which hasn’t already been added and replace existing transports’
  17. capacities with the new ones.
  18. After the “ready” command, you will start receiving groups for various cities in the format: “{city} {peopleCount}”
  19. until you receive “travel time!”.
  20. After that, calculate whether the group will have enough seats to accommodate the passengers and print the status per
  21. these conditions:
  22. If the group’s size is smaller than or equal to the combines seats in all the vehicles, print:
  23. - “{city} -> all {peopleCount} accommodated”
  24. If the group’s size is larger than the combines seats in all the vehicles, print:
  25. - “{city} -> all except {peopleCount - transportCapacities} accommodated”
  26. Constraints
  27. - There will be no redundant whitespaces anywhere in the input.
  28. - The input will always be in the format specified.
  29. - The group cities will always be existing cities.
  30. - The group sizes will always be positive.
  31. EXAMPLES:
  32.    INPUT <<<
  33. Athens:bus-40,airplane-300,train-150
  34. Athens:minibus-8,airplane-350
  35. Warsaw:bus-30,train-150,airplane-120
  36. ready
  37. Athens 400
  38. Warsaw 500
  39. travel time!
  40.    OUTPUT:
  41. Athens -> all 400 accommodated
  42. Warsaw -> all except 200 accommodated
  43. """
  44.  
  45. cities = {}
  46.  
  47. while True:
  48.     command = input()
  49.     if command == "ready":
  50.         break
  51.     a = [item for item in command.split(":")]
  52.     city = a[0]
  53.  
  54.     b = [item for item in a[1].split(",")]
  55.  
  56.     for i in b:
  57.         c = [item for item in i.split("-")]
  58.         if city not in cities:
  59.             cities[city] = {}
  60.         cities[city][c[0]] = int(c[1])
  61. for city, transport in cities.items():
  62.     cities[city] = sum(transport.values())
  63.  
  64. while True:
  65.     command = input()
  66.     if command == "travel time!":
  67.         break
  68.     a = [item for item in command.split(" ")]
  69.     check_city = a[0]
  70.     value = int(a[1])
  71.     if check_city in cities:
  72.         if value <= cities[check_city]:
  73.             print(f"{check_city} -> all {value} accommodated")
  74.         else:
  75.             print(f"{check_city} -> all except {abs(cities[check_city] - value)} accommodated")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement