Take Your Vitamins
Time limit1sMemory limit128 MB
For each line of amount, unit, requirement, and name, print the rounded daily-value percentage; collect items under 1% into a trailing list.
- Level
Easy3 of 10
- Topics
- Implementation, Math, Simulation, String
- Solved
- No attempts yet
Problem
Manufacturers of food products are required to place nutrition information labels on their packages. A major part of this information is a listing of important vitamins and minerals, giving both the amount of the chemical present in one serving and the percentage of an adult's minimum daily requirement for that chemical.
Write a program that helps prepare these nutrition labels by computing that percentage from the amount present in one serving and the amount that constitutes the minimum daily requirement.
Input
The input consists of one or more lines, each of the form:
A U R V
where:
Ais the amount of a vitamin/mineral present in one serving of the food product,Uis the unit in whichAis measured,Ris the minimum daily requirement for that vitamin/mineral, measured in the same unit asA,Vis the name of that vitamin/mineral.
A and R are floating-point numbers. U is a string of alphabetic characters with no embedded spaces. V is a string of characters that may include spaces. A, U, R, and V are separated from one another by exactly one space, and V runs to the end of the line.
The input ends with a line in which A is negative.
Output
For each input line, determine the percentage of the recommended daily requirement provided for that vitamin/mineral. If that percentage is at least 1%, print a line of the form:
V A U P%
where V, A, and U are the values from the input and P is the percentage of the minimum daily requirement represented by the amount A.
V is left-justified. A is printed with 1 digit after the decimal point, and P is printed with no digits after the decimal point (rounded to the nearest integer). V, A, U, and P are separated by a single space each.
After the last such line, print the line:
Provides no significant amount of:
followed by the names of all vitamins/minerals that provide less than 1% of the minimum daily requirement, one name per line, in the order they appeared in the input.