题解 | 【模拟】#HJ25数据分类处理#

数据分类处理

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

严格来说应该是简单或者中等题。
注意两点:
1. set()会改变顺序,所以要sorted(set())
2. insert(index, obj),参数顺序易记反
3. 多用辅助变量,比2023届各大大厂的笔试题简单多
import sys

line1 = list(map(int, input().split()))
m = line1[0]
L = line1[1:]

line2 = list(map(int, input().split()))
n = line2[0]
R = line2[1:]
R = sorted(set(R))
ans = []

point = 0
for r in R:
    flag = False
    count = 0
    inject = 0
    for index, l in enumerate(L):
        if str(r) in str(l):
            if not flag:
                ans.append(r)
                flag=True
                point += 1
                inject = point
                point += 1
            ans.append(index)
            ans.append(l)
            point += 2
            count += 1
    if flag:
        ans.insert(inject,count)
    
len_ = len(ans)

ans.insert(0,len_)
print(" ".join(str(item) for item in ans))


#华为笔试#
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务