Hello, Everybody!

Ok, I urgently need the solution for a following task in C++. This is the task from programmers contest,

so I believe somebody have a solution for it.

I need either a full source code or a simple description of algorithm to solve this task.

thank a lot in advance.

Unit Conversion

A (measurement) unit is here represented by a single word containing only lower-case letters. All

units are written as singular both in input and in output. A conversion fact relates the size of two

units.

You are to convert a quantity in one unit to the equivalent quantity in a different unit using only

a given set of conversion facts. These conversion facts are self consistent; there is never more

than one conversion chain from any unit to any other unit.

Input

The input will start with a number of lines, each containing a conversion fact in the form:

<v1> <u1> = <v2> <u2>

The elements <v1> and <v2> are positive real numbers (a sequence of decimal digits, containing

at most one decimal point), and <u1> and <u2> are strings containing only lower case letters

representing the name of a unit. The elements are separated by single spaces. The conversion fact

asserts that the quantity <v1><u1> is equal to the quantity <v2><u2>.

There will then a number of lines each representing a conversion request in the form:

<v3> <u1> = ? <u2>

The elements <u1> and <u2> are again unit names, which may or may not have occurred in the

conversion facts. All elements on the line are separated by single spaces (the equality sign and

question mark are surrounded by single spaces too). The end of data is represented by end-offile.

Output

For each conversion request there should be either the line

No conversion is possible.

if insufficient conversion facts have been given, or a line of the form

<v3> <u1> = <v4> <u2>

all elements are as in the conversion request, except that the .?. has been replaced by a

decimal number <v4>, and is calculated, using only the given conversion facts previously

given, so that the left and right-hand side quantities are equal. There should be a single space

between all elements in the line. The numbers <v3> and <v4> must be formatted as follows:

<v4> is greater than or equal to 1,000,000 or less than 0.1, it must be printed in scientific

notation: a number between 1.000000 and 9.999999 printed with exactly six digits after the

decimal point, followed by .e+nn. or .e-nn., where .e. represents .times ten to the power

of., and .nn. is a two digit number.

, <v4> must be printed in standard decimal notation, with a decimal point

followed by exactly six digits.

both cases, the number printed must be the closest such number to the true answer, i.e.

round, don.t truncate.

Sample Input:

7200.0 second = 2 hour

10.0 glob = 1 decaglob

1 day = 24.0 hour

1 minute = 60 second

1 glob = 10 centiglob

1 day = 24 hour

1 year = 365.25 day

50 centiglob = ? decaglob

5.6 second = ? hour

3 millisecond = ? hour

5.6 second = ? day

1 day = ? glob

1 hour = ? second

1 year = ? second

Sample Output (corresponding to sample input)

50.000000 centiglob = 0.500000 decaglob

5.600000 second = 1.555556e-03 hour

No conversion is possible.

5.600000 second = 6.481481e-05 day

No conversion is possible.

1.000000 hour = 3600.000000 second

1.000000 year = 3.155760e+07 second

--

With best regards,

Gregory Edigarov