#C5795. Aggregate Ingredients
Aggregate Ingredients
Aggregate Ingredients
You are given a set of recipes. Each recipe contains several ingredients along with their required quantities. Your task is to aggregate the quantities of each ingredient across all recipes. The final output should list each ingredient and its total quantity in alphabetical order.
Input Format:
- The first line contains an integer n, the number of recipes.
- For each recipe:
- The first line contains an integer m, the number of ingredients in the recipe.
- The next m lines each contain a string and an integer, representing an ingredient name and its quantity.
Output Format:
- Output the aggregated quantities of each ingredient in alphabetical order by ingredient name.
- Each line should contain an ingredient name and its total quantity separated by a space.
Example:
Input: 3 3 flour 200 sugar 100 egss 2 3 flour 150 sugar 100 butter 50 3 milk 200 sugar 50 eggs 1</p>Output: butter 50 eggs 3 flour 350 milk 200 sugar 250
inputFormat
The first line contains an integer n
indicating the number of recipes. For each recipe, the first line contains an integer m
representing the number of ingredients. The following m
lines each contain an ingredient (a string without spaces) and an integer quantity separated by a space.
outputFormat
Output the aggregated quantities for each ingredient in alphabetical order by ingredient name. Each output line should contain the ingredient and its total quantity separated by a space.
## sample3
3
flour 200
sugar 100
eggs 2
3
flour 150
sugar 100
butter 50
3
milk 200
sugar 50
eggs 1
butter 50
eggs 3
flour 350
milk 200
sugar 250
</p>