407218: GYM102697 189 Journey to the Exoplanets
Description
You're on an intergalactic space mission in the year 2100, and you come across a star with several planets orbiting it. You know the coordinates of each planet in 3D space, and given this information, you need to find the ordering of the planets from closest to farthest away from the star. Then, you can figure out which planets are most likely to have alien life forms.
You're given the coordinates of the star of the planetary system, and the coordinates for $$$n$$$ planets orbiting the star, and their names.
Recall that you can use the 3D distance formula to calculate the distance between two planets in 3D space:
The first line of input consists of three space-separated integers: the X, Y, and Z coordinates of the star, respectively.
The next line of input contains a single positive integer $$$n$$$: the number of planets orbiting the star.
The next $$$n$$$ lines each contain three space-separated integers, representing the X, Y, and Z coordinates of each planet, respectively, followed by a space and a single string, representing the name of the planet.
No two planets in the input file will have the same distance away from the star.
OutputOutput $$$n$$$ lines: the names of each planet in the exoplanetary system, ordered based on their distance from the star. The planet closest to the star should come first in the list, and the planet the furthest away from the star should come last in the list.
ExampleInput20 20 20 8 16 19 20 Venus 10 20 20 Mars 14 22 20 Earth 18 20 20 Mercury -5 17 20 Uranus 2 21 21 Saturn 6 20 23 Jupiter -11 20 21 NeptuneOutput
Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune