← 返回 stripe 的题目列表Shipping Cost Lookup and Transit Route Optimization
类型:online_judge
stripe
Question 1
Given a string containing shipping cost information between different countries, with each entry including the source country, destination country, carrier, and cost. Implement a function to return the shipping cost between specified countries and with a specified carrier.
Input format:
shipping_info (string): A string containing shipping information, with each entry separated by a semicolon and formatted as <source_country>,<destination_country>,<carrier>,<cost>.
source (string): The source country.
destination (string): The destination country.
carrier (string): The carrier.
Output format:
An integer representing the cost according to specified conditions. Return -1 if no matching information is found.
Sample Input:
shipping_info = "US,UK,FedEx,100;UK,FR,FedEx,80;US,FR,UPS,120"
source = "US"
destination = "UK"
carrier = "FedEx"
Sample Output:
100
Question 2
With allowance for one transit, return the transit route from the source country to the destination country, including the transit path, carrier used, and cost.
Input format:
Same as Question 1.
Output format:
A list containing formatted string information of transit routes, with each entry as <source_country> -> <transit_country> -> <destination_country> via <carrier> with cost <cost>. Return an empty list if no suitable transit plan is found.
Sample Input:
shipping_info = "US,UK,FedEx,100;UK,FR,FedEx,80;US,FR,UPS,120"
source = "US"
destination = "FR"
carrier = "FedEx"
Sample Output:
["US -> UK -> FR via FedEx with cost 180"]
Question 3
Find the minimum shipping cost from source country to destination country with allowance for one transit.
Input format:
Same as Question 1.
Output format:
An integer representing the minimum possible cost. Return -1 if no suitable route is found.
Sample Input:
shipping_info = "US,UK,FedEx,100;UK,FR,FedEx,80;US,FR,UPS,150;FR,US,FedEx,200"
source = "US"
destination = "FR"
Sample Output:
180
Example
Input
"US,UK,FedEx,100;UK,FR,FedEx,80;US,FR,UPS,120\nUS\nUK\nFedEx"
Output
""