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 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn