je30824 2016-04-13 12:54 采纳率: 0%
浏览 1278
已结题

请教map list容器问题

请问这个题目怎么用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 }

  • 写回答

1条回答 默认 最新

  • devmiao 2016-04-13 13:49
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog