← 返回 bytedance 的题目列表Currency Conversion
类型:online_judge
You are given a list of currency exchange rates. Each exchange rate is represented as:
[fromCurrency, toCurrency, rate]
meaning:
1 fromCurrency = rate * toCurrency
You are also given multiple queries. For each query:
[sourceCurrency, targetCurrency]
return the exchange rate from sourceCurrency to targetCurrency. If the conversion is not possible, return -1.0.
Input Format
rates: A list of lists, where each sub-list contains three elements representing the exchange rate.
queries: A list of queries, where each query is a list of two strings.
Output Format
Return a list of floats representing the results of each query.
Example
Input
rates = [
["USD","EUR",0.9],
["EUR","JPY",120.0]
]
queries = [
["USD","JPY"],
["JPY","USD"],
["USD","GBP"]
]
Output
[108.0, 1/108.0, -1.0]
Example
Input
USD EUR 0.9
EUR JPY 120.0
USD JPY
JPY USD
USD GBP