WC '02 P3 - The Big Book of Recipes

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem type
Woburn Challenge 2002

So how is the monkeys' meeting going, you ask? Well, the Head-Monkey is quite big on food and whenever there's a meeting atop the Enchanted Tree, it is a necessity that dinner is served (pun intended). What the monkeys don't realize is that the Head-Monkey is not really a good cook. But then, how many army leaders are good cooks? The answer is, none. This time, the Head-Monkey has purchased a cookbook. The cookbook has a certain number of recipes, but any recipe may require an ingredient which must be prepared according to some other recipe! This is all quite confusing for the Head-Monkey. She wants you to tell her how much of each base ingredient she needs for her recipe.

Input Specification

The first line of input contains a single integer, T (1 \le T \le
50), indicating the number of test cases.

The first line of each test case will contain N (1 \le N \le 20), the total number of ingredients to follow. For each ingredient, there follows a line with that ingredients name - if the ingredient is a basic ingredient it will be in lowercase letters, if there is a recipe in terms of other ingredients for it, its name will be in capital letters.

For each non-basic ingredient, a recipe for one serving of that ingredient will follow (format: an integer k, 1 \le k \le 20, indicating the number of ingredients in that recipe, then a series of lines of the form [number of servings of ingredient required, space, ingredient required]).

Finally, there will be an ingredient name - you are to determine the amount of each basic ingredient required to make one serving of that ingredient.

Output Specification

A series of lines of the form [number of servings of ingredient required, space, ingredient required], containing only basic ingredients. Output them in the same order as they were listed in the input.
Leave a blank line between test cases.

Sample Input

1.5 milk
0.25 salt
1 bread
1 turkey
1 ham
0.3 MAYO
0.2 egg
0.1 vinegar
0.1 salt

Sample Output

3.3 milk
0.58 salt
1 turkey
1 ham
0.06 egg
0.03 vinegar
1 bread


There are no comments at the moment.