2019秋招马蜂窝数据开发:第一题

# input:1-beijing 1-guilin 2-shanghai 3-shanghai 4-qingdao 5-dalian
s = input()
res = list(map(str, s.split()))
d = {}
for x in res:
    s1,s2 = x.split('-')
    s1 = int(s1)
    if s2 not in d:
        d[s2] = [s1]
    else:
        d[s2].append(s1)
for i in d:
    d[i] = len(set(d[i]))
ans = sorted(d.items(),key=lambda x:(-x[1],x[0]))[:3]
for x in ans:
    print(x[0],x[1])

 

你可能感兴趣的:(python3)