#C3694. Grouping Commodities by Fragility
Grouping Commodities by Fragility
Grouping Commodities by Fragility
You are given a list of commodities. Each commodity is described by three attributes: a name (a string), a weight (a floating point number), and a fragility classification (a string). The fragility classification will be one of the following:
Fragile
Non-Fragile
Extremely Fragile
Your task is to group the commodities according to their fragility level. For each group, you must output the group in a fixed order (Fragile
, Non-Fragile
, then Extremely Fragile
).
The output for each group should have the following format:
- The group name on a single line.
- The number of commodities in that group on the next line.
- Then, for each commodity in that group (in the order they appear in the input), output a line with the commodity name and weight separated by a space.
If there are no commodities for a specific group, simply print the group name followed by a line with 0.
For example, if the input is:
5 Vase 2.5 Fragile Book 1.2 Non-Fragile Mirror 3.0 Extremely Fragile Laptop 1.5 Fragile Chair 5.0 Non-Fragile
Then the expected output is:
Fragile 2 Vase 2.5 Laptop 1.5 Non-Fragile 2 Book 1.2 Chair 5.0 Extremely Fragile 1 Mirror 3.0
Note: All floating point numbers should be output exactly as provided in the input.
In mathematical notation, if you let \(S = \{(n_i, w_i, f_i)\}\) be the set of commodities, then for each fragility group \(f \in \{\text{Fragile, Non-Fragile, Extremely Fragile}\}\), you are to compute the subset \(S_f = \{(n_i, w_i) \mid f_i = f\}\).
inputFormat
The input is read from standard input and has the following format:
- An integer \(N\) representing the number of commodities.
- Then \(N\) lines follow, each containing three tokens:
- A string representing the commodity name.
- A floating point number representing the commodity weight.
- A string representing the fragility classification (will be exactly one of three values: "Fragile", "Non-Fragile", or "Extremely Fragile").
There are no extra spaces and all tokens are separated by whitespace.
outputFormat
The output should be printed to standard output in the following order for each fragility group (Fragile
, Non-Fragile
, Extremely Fragile
):
- Print the group name.
- Print the number of items in that group.
- For each commodity in that group (maintaining the order of appearance in the input), print a line with the commodity name and weight separated by a space.
Each of these items should be printed on its own line.
## sample5
Vase 2.5 Fragile
Book 1.2 Non-Fragile
Mirror 3.0 Extremely Fragile
Laptop 1.5 Fragile
Chair 5.0 Non-Fragile
Fragile
2
Vase 2.5
Laptop 1.5
Non-Fragile
2
Book 1.2
Chair 5.0
Extremely Fragile
1
Mirror 3.0
</p>