#C4004. Top Readers Board
Top Readers Board
Top Readers Board
You are given a series of log entries representing books read by members of a club. Each log entry is a string in the format Name BookTitle
where Name
is the name of the club member and BookTitle
is the title of the book they read.
Your task is to generate a "Top Readers Board" by counting the number of books read by each member and then sorting the result. The sorting criteria is as follows:
- Primary: Descending order of the number of books (i.e., a member with more books read appears first),
- Secondary: If two or more members have read the same number of books, sort them in lexicographically ascending order.
The sorting condition can be expressed by the formulas below in LaTeX:
\(\text{Sort by } count \text{ in descending order, and by } name \text{ in ascending order:} \\orall\, (n_i,c_i), (n_j,c_j), \ (c_i > c_j) \lor (c_i = c_j \wedge n_i < n_j)\)
Print the resulting board where each line contains the member's name and the count separated by a space.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains an integer \(N\), representing the number of log entries.
- The following \(N\) lines each contain a log entry in the format:
Name BookTitle
. Note that theBookTitle
might contain spaces.
outputFormat
Output the Top Readers Board to standard output (stdout). Each line should contain a member's name followed by a space and the number of books they have read.
## sample1
Alice BookA
Alice 1
</p>