#K71147. Sort Students By Name
Sort Students By Name
Sort Students By Name
You are given a list of students. Each student is represented by their first name and last name. Your task is to sort these students primarily by their last names in lexicographical order; if two or more students share the same last name, then sort them by their first name.
Input Format: The input is given through stdin
. The first line contains an integer n, which represents the number of students. Each of the following n lines contains two strings: the first name and the last name of a student.
Output Format: Print the full name of each student (in the format "first_name last_name") on a separate line, following the specified sorted order.
Note: If no students are given (i.e. n = 0
), no output should be produced.
inputFormat
The first line contains an integer n
(0 ≤ n ≤ 105), representing the number of students. Each of the next n
lines contains two space-separated strings: the first name and the last name. Each name will consist of alphabetical characters only.
outputFormat
Output n
lines. Each line should contain the student's full name in the format first_name last_name, sorted by last name first, and by first name if the last names are identical.
5
John Doe
Jane Smith
Alice Doe
Bob Brown
Charlie Brown
Bob Brown
Charlie Brown
Alice Doe
John Doe
Jane Smith
</p>