Route optimization using structures and a priority queue

Swift Hard structs

Task «Route optimization using structures and a priority queue»

Develop a `Route` structure representing a route with fields: `startCity` (String), `endCity` (String), `distance` (Int), and `priority` (Int). Implement a function `optimizeRoutes` that takes an array of routes and returns a sorted array of routes in ascending order of distance, and for equal distances, in descending order of priority. Then, for each route, print its description in the format: "{startCity} -> {endCity}: {distance} km (priority {priority})". If the array is empty, print "No routes". Use only structures and built-in sorting algorithms, without classes.

Input Format

The first line contains an integer N (1 ≤ N ≤ 100) — the number of routes. Then follow N lines, each containing four values separated by a space: startCity (a string without spaces, up to 20 characters), endCity (a string without spaces, up to 20 characters), distance (an integer from 1 to 10000), priority (an integer from 1 to 100).

Output Format

Output N lines, each in the format "{startCity} -> {endCity}: {distance} km (priority {priority})", sorted according to the rule. If N=0, output "No routes".

Examples

Example 1

INPUT
3 X Y 1000 10 Y Z 500 10 Z X 750 10
OUTPUT
Y -> Z: 500 km (priority 10) Z -> X: 750 km (priority 10) X -> Y: 1000 km (priority 10)

Example 2

INPUT
1 Start End 1 100
OUTPUT
Start -> End: 1 km (priority 100)
main.swift