#C39. Sort Books by Title and Author
Sort Books by Title and Author
Sort Books by Title and Author
You are given a list of books, each defined by a title and an author. Your task is to sort the books in lexicographical (alphabetical) order first by their title. If two or more books have the same title, then sort those books by the author's name in lexicographical order.
The sorting criteria can be mathematically expressed as follows:
After sorting, output the list where each book is printed on a separate line with the title and author separated by a space.
inputFormat
The first line contains an integer n
, representing the number of books. Each of the following n
lines contains two strings: the title
of the book and its author
, separated by a space.
outputFormat
Output the sorted list of books. Each line should contain the title and author of a book, separated by a space. The books must be sorted first by title and then by author.
## sample3
HarryPotter Rowling
TheHobbit Tolkien
HarryPotter Reed
HarryPotter Reed
HarryPotter Rowling
TheHobbit Tolkien
</p>