First and Last
Whitcombe Legal keeps its client index alphabetised by surname, so an index line has to lead with the surname rather than the given name. The intake form, meanwhile, asks for a full name in the ordinary spoken order — given name first — because that is what clients expect to type. Every record therefore has to be turned around before it can be filed.
Task: Print each name rearranged into index order.
Input
The first line holds one integer n, how many names follow. Each of the next n lines holds exactly two words separated by a single space: the given name, then the surname. Every line has exactly two words, and both are lowercase.
Output
n lines in the same order as the input. Each line holds the surname, then a comma, then one space, then the given name.
Example:
Input:
2
ada lovelace
alan turing
Output:
lovelace, ada
turing, alan
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in