← 返回 meta 的题目列表City Name by Population Probability
类型:online_judge
meta
Given several city names and their corresponding populations, implement an API to return a city's name based on the probability proportion of its population.
Input
List of tuples, each containing a city name (string) and its population (integer).
Output
A string representing the city name, selected based on the proportion of its population.
Test Case
cities = [
("CityA", 100),
("CityB", 300),
("CityC", 600)
]
output = "CityB" # Randomly generated depending on the probability proportion.
Implement a method pick_city() that returns a city name based on the population proportion.
Example
Input
[("CityA", 10), ("CityB", 30), ("CityC", 60)]