请问这个题目怎么用c++实现
Write a Python function called tally that consumes a list of strings representing all the
participant’s town visits (called log) and produces a dictionary with the participants as the keys
and the total points earned as the corresponding values. Notes:
• Each element in log is a string with three comma separated values: the first value is the
participant id, the second is the town, and the third is the points earned in that town.
• If the participant visited a town more than once, then tally must assign None to that
participant’s total points to show they are disqualified.
• The list tally may be empty, but all strings in tally will be in the correct format.
• Recall dictionaries do not have an associated order: two dictionaries are equal if they
have the same set of keys, and each key has the same associated value. This means your
produced dictionary may have keys in any order when printed.
Example 1:
tally([ "jsmith,Elora,2",
"jsmith,St. Jacobs,4",
"klee,Elora,3",
"proth,Conestogo,4",
"kafka,Heidelberg,2",
"klee,Heidelberg,5",
"kafka,Elora,1",
"klee,St. Jacobs,5",
"jsmith,Heidelberg,1"])
=> { "jsmith" : 7, "klee" : 13, "kafka" : 3, "proth" : 4 }
Example 2:
tally([ "ricky,Linwood,4",
"janed,Linwood,3",
"janed,Wallenstein,2",
"ricky,Linwood,5",
"mog,Conestogo,2"])
=> { "mog" : 2, "ricky" : None, "janed" : 5 }
请教map list容器问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-