PTA天梯赛练习题-帅到没朋友,求指出问题所在


n = int(input())
list1 = []
list2 = []
list3 = []
for i in range(n):
    s = str(input())
    if s[0] == '1':
        list2.append(int(s[2:7]))
        continue
    elif s[0] == '0':
        continue
    else:
        for j in range(int(s[0])):
            list1.append(int(s[(2+6*j):(7+6*j)]))
list1 = list(set(list1))
m = int(input())
s1 = str(input())
for i in range(m):
    list2.append(int(s1[(0+i*6):(5+6*i)]))
for i in range(len(list2)):
    for j in range(len(list1)):
        if list2[i] == list1[j]:
            list3.append(list2[i])
list = list(set(list2)-set(list3))
if list == []:
    print('No one is handsome')
else:
    for i in range(len(list)):
        if i == len(list)-1:
            print(list[i])
        else:
            print(list[i],end=' ')

上面就是我写的代码,实在想不出问题所在


a = int(input())
empty1 = []
handsome = []
getid = []

check = []
amount = 0
for i in range(a):
    b = input().split(" ")
    b = list(map(lambda x: int(x),b))
    if b[0] == 1:
        handsome.append(b[1])
    getid += b[1:]
    print(getid)

c = int(input())
d = input().split(" ")
d = list(map(lambda x: int(x),d))

for i in d:
    if i not in getid:
        handsome.append(i)

real = sorted(set(handsome),key=handsome.index)
if len(handsome) == 0:
    print("No one is handsome")
else:
    print(*real)

给你简化了一下