The money trail
Description
Discuss (7 comments)
This puzzle is a follow up on the Currency converter puzzle. The goal is still to convert one currency into another however with some added difficulty.
The input file is formatted as follows:
Important: There is no default currency, and consequently it is not always possible to convert a currency into another.
Example:
It should contain p lines, one for each currency conversion query giving the amount in the target currency, if the currency cannot be converted then the value 0 should be printed instead.
Important: The output result must be printed with exactly 4 fractional digit accuracy. The only exception is for the 0 indicating that a conversion is not possible.
For the previous example, the solution is:
Input Specifications
Your program must take one and only one command line argument: the input file.The input file is formatted as follows:
- the first line contains the number n of currencies exchange rates
- the n following lines each contain a currency equivalence of the form
rate1 currency1 = rate2 currency2 - the next line contains the number p of conversions queries
- the p following lines each contain a currency conversion query of the form
amount source_currency => target_currency
Important: There is no default currency, and consequently it is not always possible to convert a currency into another.
Example:
4 1 Euro = 1.4025 Dollar 2.5 Dollar = 70.5482 Ruble 5.5 Rupee = 3.4749 Ruble 0.7 Pound = 1.7516 Real 4 10 Dollar => Euro 25 Euro => Rupee 1.5 Ruble => Real 5.50 Real => Pound
Output Specifications
You must print your output to the standard output (printf, etc...).It should contain p lines, one for each currency conversion query giving the amount in the target currency, if the currency cannot be converted then the value 0 should be printed instead.
Important: The output result must be printed with exactly 4 fractional digit accuracy. The only exception is for the 0 indicating that a conversion is not possible.
For the previous example, the solution is:
7.1301 1566.0628 0 2.1980Example explanation:
- The value 7.1301 is simply computed by using the first exchange rate (Euro -> Dollar)
- The value 1566.0628 is computed by combining the first 3 exchange rates (Euro -> Dollar -> Ruble -> Rupee).
- The value 0 reflects the fact that with the given exchange rates, it's impossible to convert from Ruble to Real
Scoring
The number of points is determined by the tests that are passed. You can see in the Unit Tests section for how many percent each test success contributes to the final score.© CoderCharts - All Rights Reserved
| Type | Puzzle | Pass | 165 | Fail | 59 | ||
| Scoring | Generic | Level | Medium | Points | 900 | ||
| Tags | arithmetic, conversion, recursion | ||||||
Unit Tests
| Name | CPU Unit | Memory Unit |
|---|---|---|
Small(10% of the score) 12 currencies, 99 conversions |
||
Medium(20% of the score) 50 currencies, 501 conversions |
||
Large(30% of the score) 100 currencies, 10000 conversions |
||
Extreme(40% of the score) 500 currencies, 10000 conversions |
Confirm that you want to switch languages
Your current edits will be lost.
Confirm that you wish to load a previous submission
Your current edits will be lost.