#C1615. Sorting Points by Euclidean Distance
Sorting Points by Euclidean Distance
Sorting Points by Euclidean Distance
You are given n points in a coordinate space. Each point is identified by a unique string followed by its coordinates. The coordinates can be in an arbitrary number of dimensions. Your task is to sort these points in ascending order based on their Euclidean distance from the origin.
The Euclidean distance of a point \( (x_1, x_2, \ldots, x_k) \) from the origin is given by the formula:
\( d = \sqrt{x_1^2 + x_2^2 + \cdots + x_k^2} \)
If two points share the same distance, maintain their original input order.
inputFormat
The first line of input contains an integer n, the number of points.
Each of the next n lines describes a point. Each line starts with a string (the identifier of the point), followed by one or more integers representing its coordinates. All values are separated by spaces.
outputFormat
Output a single line containing the identifiers of the points sorted by their Euclidean distance from the origin, separated by a single space.
## sample3
pointA 1 2
pointB 2 3
pointC 3 4
pointA pointB pointC