题解 | #数据分类处理#

数据分类处理

http://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd

# 输入
I = input().split()[1:]
R = map(str,sorted(map(int,set(input().split()[1:]))))
# 匹配满足条件的I
res = []
for i in R:
    # 临时存储结果,为了后面在最前面加入数量
    tempI = []
    for j in range(len(I)):
        if i in I[j]:
            tempI.append(j)
            tempI.append(I[j])
    # 加入数量
    if tempI:
        res.append(i)
        res.append(int(len(tempI)/2))
        for j in tempI:
            res.append(j)
result = [len(res)]
for i in res:
    result.append(i)
for i in result:
    print(str(i)+' ',end='')

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务