#C13209. Multi-Criteria Sorting of People

    ID: 42722 Type: Default 1000ms 256MiB

Multi-Criteria Sorting of People

Multi-Criteria Sorting of People

You are given a list of people, where each person is represented by a record containing three attributes: name (a string), age (an integer), and score (an integer). Your task is to sort these records according to the following rules:

  1. Primary sort: by score in descending order.
  2. Secondary sort: by age in ascending order.
  3. Tertiary sort: by name in alphabetical order.

If any record is missing one or more of these keys, your program should output an error message:

$$Error: Each record must contain 'name', 'age', and 'score' keys. $$

The solution must read input from stdin and print the output to stdout.

inputFormat

The input is provided via stdin in the following format:

The first line contains an integer n, the number of people. Each of the following n lines contains three tokens separated by spaces: name (a string), age (an integer), and score (an integer).

For example:

3
John 25 90
Alice 30 95
Bob 25 90

outputFormat

Print a single line containing the sorted names separated by a space if the input is valid. If any record is missing one or more tokens, print:

$$Error: Each record must contain 'name', 'age', and 'score' keys.$$## sample
3
John 25 90
Alice 30 95
Bob 25 90
Alice Bob John
$$