F009B. The toys of the nursery

The end of course is near! In a nursery, the educators have collected
information about the toys that each girl and each boy like. To do it,
the educators ask the children which is the toy they want to play with,
and write down in a list the name of the boy/girl and the chosen toy.

The educators have asked you to write a program that counts the number
of appearances of each pair child/toy.

Input

The input starts with a natural number n ≥ 1. Afterwards, there is a
list with the n pairs of child’s name/toy. The names of the children are
formed only by lowercase letters and digits.

Output

For each pair child/toy, print a line indicating how many times appears
this pair. The list must be sorted by the name of the child, using the
name of the toy as second criterion. Follow the format of the instances.

Observation

Some input lists can be very large. For this reason, your program must
be efficient. We suggest you to use the function |sort()| to sort tuples
(|struct|s).

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:24:29.062Z

© Jutge.org, 2006–2026.
https://jutge.org
