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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料