题解 | #数据分类处理#

数据分类处理

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

python3数据分类处理

# 序列I:15,123,456,786,453,46,7,5,3,665,453456,745,456,786,453,123
# 序列R:5,6,3,6,3,0
def func(I,R):
    res=[]
    I = I[1:]
    R = [str(i) for i in sorted(list(set(R[1:])))]#数据处理原因是,直接对字符串排序 26 会排在3前面,导致后面输出顺序和答案不一致,这里先对int型去重排序然后转化成字符串
    for i in range(len(R)):
        tmp = []
        l = []
        for j in range(len(I)):
            if R[i] in I[j]:
                tmp.append(j)
                tmp.append(I[j])
                l.append(I[j])
        if len(tmp) > 0:
            res.append(R[i])
            res.append(len(l))
            res+=tmp
    print(len(res),end=' ')
    for i in res:
        print(int(i),end=' ')
while True:
    try:
        I = input().split()
        R = list(map(int,input().split()))
        func(I,R)
    except:
        break

全部评论

相关推荐

sagima:然后这个帖子又登上了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务