Sorting an array of pointers to structures

C++ Medium pointers

Task «Sorting an array of pointers to structures»

Given a structure `Person` with fields `name` (string) and `age` (integer). Create an array of pointers to `Person` structures. Fill the array with data read from standard input. Sort the array of pointers by age (in ascending order) using the `qsort` function. If ages are equal, sort by name in lexicographic order. Output the sorted list in the format: name age. Constraints: number of entries n (1 ≤ n ≤ 100), name length no more than 50 characters.

Input Format

First line: an integer n — the number of entries. Then n lines, each containing a name and age separated by a space.

Output Format

n lines, each containing a name and age separated by a space, sorted by age (in ascending order), and if ages are equal, sorted by name in alphabetical order.

Examples

Example 1

INPUT
3 Alice 25 Bob 20 Charlie 25
OUTPUT
Bob 20 Alice 25 Charlie 25

Example 2

INPUT
2 Zara 30 Yan 30
OUTPUT
Yan 30 Zara 30

Example 3

INPUT
4 4 1 2 1 2 3 2 1 3 4 3 4 1 1 4
OUTPUT
4
main.cpp