#K76677. Sort Names by Scores

    ID: 34696 Type: Default 1000ms 256MiB

Sort Names by Scores

Sort Names by Scores

You are given multiple lines of input from standard input. Each line, except possibly the last, contains a string in the format Name:Score where Name is a person's name and Score is a non‐negative integer. The list of records should be processed to sort the names according to their scores in descending order. If two or more names share the same score, they should be sorted in ascending alphabetical order.

An optional terminal line containing end may be provided, which should not be processed as a record.

The sorting criteria can be expressed mathematically as follows: Given two records with scores \( s_i \) and \( s_j \) and names \( n_i \) and \( n_j \), then record \( i \) comes before record \( j \) if and only if \[ (s_i > s_j) \quad \text{or} \quad (s_i = s_j \quad \text{and} \quad n_i < n_j), \] where the comparison \( n_i < n_j \) denotes the lexicographical order.

inputFormat

The input is provided via standard input (stdin) as several lines. Each non-empty line has one of the following formats:

  • Name:Score – where Name is a string without spaces and Score is a non-negative integer.
  • An optional line end indicating the end of the records. If this line is not provided, all lines should be processed.

You may assume there will be at least one record.

outputFormat

Output to standard output (stdout) the list of names sorted as described. Each name should be printed on a new line in the final sorted order.

## sample
John:45
end
John