Problema de Março de 2005: Stem-and-Leaf Plots
Este foi o problema A da 1ª edição da TIUP2005, em Aveiro. Resolvi-o em pouco mais de 6 minutos :) É muito fácil de tiverem conhecimento da STL (C++), nomeadamente do std::set e do std::map. Se quiserem testar a vossa solução, podem fazê-lo durante algum tempo em mooshak.pisharp.org.
Problem
The program should draw a stem-and-leaf plot for a
sample containing positive integer numbers.
The definition of this kind of plot is the following:
-
for each element of the sample,
separate the least significant digit from the rest
of the digits: let the least significant digit to be the
`leaf' (folha), and the rest of the digits to be the `stem' (caule).
- Place a line for each different stem.
- In front of each equal stem are all leaves. (So leaves are placed in
columns.)
- Sort stems and leaves.
Input
The input is a column of integers.
-
The first integer is the length of the sample.
- Other integers are sample elements not necessarily sorted.
- One assumes the input to be lower than 1000.
Output
The stem-and-leaf plot is the output.
-
Each line contains a different stem number which groups
all leaves with equal stem in front of it.
- Stems are sorted, line by line.
- Leaves, in front of each stem, are also sorted.
- The separation of stems and leaves is made by a dot `.'.
- This dot, in each line, must occupy the 3th column.
- Space char must fill empty space until stem. Please, see spaces in Sample Output.
Sample Input
7
4
4
5
10
12
137
999
Sample Output
0.445
1.02
13.7
99.9