從這裡開始 你可以試著用 def()
去定義
set 是很好用的東西
這一單元的題目不難
print(len(set(input().split())))
print(len(set(input().split()) & set(input().split())))
print(*sorted(set(input().split()) & set(input().split()), key=int))
numbers = [int(s) for s in input().split()]
occur_before = set()
for num in numbers:
if num in occur_before:
print('YES')
else:
print('NO')
occur_before.add(num)
def print_set(some_set):
print(len(some_set))
print(*[str(item) for item in sorted(some_set)])
N, M = [int(s) for s in input().split()]
A_colors, B_colors = set(), set()
for i in range(N):
A_colors.add(int(input()))
for i in range(M):
B_colors.add(int(input()))
print_set(A_colors & B_colors)
print_set(A_colors - B_colors)
print_set(B_colors - A_colors)
words = set()
for _ in range(int(input())):
words.update(input().split())
print(len(words))
n = int(input())
all_nums = set(range(1, n + 1))
possible_nums = all_nums
while True:
guess = input()
if guess == 'HELP':
break
guess = {int(x) for x in guess.split()}
answer = input()
if answer == 'YES':
possible_nums &= guess
else:
possible_nums &= all_nums - guess
print(' '.join([str(x) for x in sorted(possible_nums)]))
students = [{input() for j in range(int(input()))} for i in range(int(input()))]
known_by_everyone, known_by_someone = set.intersection(*students), set.union(*students)
print(len(known_by_everyone), *sorted(known_by_everyone), sep='\n')
print(len(known_by_someone), *sorted(known_by_someone), sep='\n')
你➕1了沒 台灣首發晶片設計教材要開始募資啦
趕快點擊去了解 👉 https://wlinny.com