Problem J
Units
The use of units is ubiquitous in science. Physics uses units to distinguish distance (e.g., meters, kilometers, etc.), weight (e.g., kilograms, grams), and many other quantities. Computer scientists have specialized units to describe storage capacity (e.g., kilobytes, megabytes, etc.). You are to write a program to display the conversion factors for a set of units.
Specifying the relationship between various units can be
done in many different, but equivalent, ways. For example, the
units for metric distance can be specified as the group of
relationships between pairs for units:
For this problem, the units are to be sorted according to
their descending size. For example, among the length units cm,
km, m, mm, km is considered the biggest unit since
This problem is limited to unit-systems whose conversion
factors are integer multiples. Thus, factors such as
Input
The input consists of several problems. Each problem begins
with the number of units,
The sentinel value of
Output
For each set of units, produce one line of output that contains the equivalent conversions. The conversions should be sorted left to right, with the largest unit appearing on the left. The conversion factors should be defined with respect to the leftmost unit (i.e., the largest unit) and should be separated by “ = ”.
Sample Input 1 | Sample Output 1 |
---|---|
4 km m mm cm km = 1000 m m = 100 cm cm = 10 mm 4 m mm cm km km = 100000 cm km = 1000000 mm m = 1000 mm 6 MiB Mib KiB Kib B b B = 8 b MiB = 1024 KiB KiB = 1024 B Mib = 1048576 b Mib = 1024 Kib 6 Kib B MiB Mib KiB b B = 8 b MiB = 1048576 B MiB = 1024 KiB MiB = 8192 Kib MiB = 8 Mib 0 |
1km = 1000m = 100000cm = 1000000mm 1km = 1000m = 100000cm = 1000000mm 1MiB = 8Mib = 1024KiB = 8192Kib = 1048576B = 8388608b 1MiB = 8Mib = 1024KiB = 8192Kib = 1048576B = 8388608b |