← 返回 coinbase 的题目列表Currency Exchange
类型:online_judge
Currency Exchange
Given a set of exchange rates, find the best exchange rate between two currencies. The rates can be represented as a directed graph where nodes represent currencies and edges represent exchange rates. Given three inputs: starting currency code, target currency code, and all currency exchange paths, output the optimal exchange rate.
Input:
Four lines of input, each in separate lines.
Starting currency code (string)
Target currency code (string)
Total currency count (n)
List of all exchange rates, each element is a string representing exchange rate information between two currencies
Output:
Optimal exchange rate (float)
Example:
USD
EUR
3
USD->JPY,100.0
JPY->EUR,0.01
USD->EUR,1.5
Output: 1.5
Constraints:
Exchange rates may contain up to 1 million records.
Example
Input
USD
EUR
3
USD->JPY,100.0
JPY->EUR,0.01
USD->EUR,1.5