#K38897. Sort Names by Last and First Name
Sort Names by Last and First Name
Sort Names by Last and First Name
You are given a list of names, each in the format Title FirstName LastName
. Your task is to sort these names primarily by the last name and secondarily by the first name. The title should be ignored in the sorting process.
For example, if you are given the names: "Dr. John Smith", "Ms. Jane Doe", and "Mr. Sam Brown", the sorted order should be:
- Mr. Sam Brown
- Ms. Jane Doe
- Dr. John Smith
Implement your solution so that it reads input from standard input (stdin) and writes the output to standard output (stdout). Ensure that your code passes all the test cases provided.
inputFormat
The first line contains an integer N, which represents the number of names. The next N lines each contain a name in the format Title FirstName LastName
.
outputFormat
Output the sorted list of names, one per line. The names should be sorted primarily by last name and secondarily by first name.
## sample3
Dr. John Smith
Ms. Jane Doe
Mr. Sam Brown
Mr. Sam Brown
Ms. Jane Doe
Dr. John Smith
</p>