#K91062. Record Sorting
Record Sorting
Record Sorting
You are given a list of records, each containing an integer identifier and a music genre represented as a string. The task is to sort these records first by the genre in lexicographical order and then by the identifier in numerical order when the genres are the same.
For instance, if two records have the same genre, the one with the smaller identifier should appear first.
Note: The input is read from standard input and the sorted records must be printed to standard output.
inputFormat
The input starts with an integer n representing the number of records. The following n lines each contain a record. Each record consists of an integer identifier and a string representing the genre, separated by a space.
Example:
4 102 rock 101 jazz 103 jazz 104 rock
outputFormat
The sorted records are printed to standard output. Each line should contain a record with the identifier and genre separated by a space. The records must appear in sorted order according to the rules described: first sorted lexicographically by genre and then numerically by identifier if genres are equal.
Example Output for the above input:
101 jazz 103 jazz 102 rock 104 rock## sample
4
102 rock
101 jazz
103 jazz
104 rock
101 jazz
103 jazz
102 rock
104 rock
</p>