Currency desk conversion ledger
A travel-money desk at an airport quotes every currency against the US dollar. The rate table says how many units of each currency you get for 1 USD. To convert between two non-dollar currencies the desk goes through USD: divide by the source rate, then multiply by the target rate.
Task: the first line is n, the number of rates. The next n lines are CODE rate (the table always includes USD 1). Then a line with m, the number of requests, followed by m lines amount FROM TO. For each request print one line RESULT TO. Compute amount / rate_FROM * rate_TO exactly with the decimal module (default precision, do not round the in-between USD value), then round once: JPY has 0 decimals, every other currency has 2 decimals, halves rounded up. Print JPY without a decimal point, for example 15130 JPY and 92.00 EUR.
Sample tests
Input
6 USD 1 EUR 0.92 GBP 0.79 INR 83.2 JPY 151.3 BRL 5.05 3 100 USD EUR 250.50 GBP JPY 1000 INR BRL
Expected output
92.00 EUR 47976 JPY 60.70 BRL
Input
4 USD 1 PKR 278.5 EUR 0.92 JPY 151.3 3 50000 PKR EUR 12345 JPY PKR 0.01 EUR PKR
Expected output
165.17 EUR 22723.61 PKR 3.03 PKR
Your answer is also checked against 3 hidden tests.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
