#C2575. Library Books Sorting Problem

    ID: 45906 Type: Default 1000ms 256MiB

Library Books Sorting Problem

Library Books Sorting Problem

You are given several datasets of library books. Each dataset begins with an integer indicating the number of books (this number is only used as a marker and can be ignored). This is followed by that number of book records, where each record is a string in the format "serial_number title". The input ends with a line containing 0.

Your task is to sort the books in each dataset in lexicographical order by their title. In case of a tie (i.e. identical titles), sort by the serial number in ascending order. Finally, concatenate the sorted results of each dataset in the order they appear and output each record on a new line.

Note: The sorting criteria can be mathematically described as sorting by \( (\text{title},\,\text{serial_number}) \) where the title is compared lexicographically and the serial number numerically.

inputFormat

The input is read from standard input (stdin). It consists of multiple lines. The beginning of each dataset is marked by a line containing an integer (which you can ignore apart from its role as a separator), followed by that many lines each containing a record of a book in the format serial_number title. The input terminates with a line containing 0.

outputFormat

Output the sorted book records to standard output (stdout). Each record should be printed on its own line in the format serial_number title.

## sample
3
123 Hamlet
456 RomeoAndJuliet
789 Hamlet
0
123 Hamlet

789 Hamlet 456 RomeoAndJuliet

</p>