点击链接PTA-Python-AC全解汇总
题目:
给定两个整型数组,本题要求找出不是两者共有的元素。
输入格式:
输入分别在两行中给出两个整型数组,每行先给出正整数N(≤20),随后是N个整数,其间以空格分隔。
输出格式:
在一行中按照数字给出的顺序输出不是两数组共有的元素,数字间以空格分隔,但行末不得有多余的空格。题目保证至少存在一个这样的数字。同一数字不重复输出。
输入样例:
10 3 -5 2 8 0 3 5 -15 9 100
11 6 4 8 2 6 -5 9 0 100 8 1
- 1
- 2
输出样例:
3 5 -15 6 4 1
- 1
我的代码:
nums1=list(input().split())
nums2=list(input().split())
nums1.pop(0)
nums2.pop(0)
out=[]
for x in nums1:
if x not in nums2 and x not in out:
out.append(x)
for x in nums2:
if x not in nums1 and x not in out:
out.append(x)
print(" ".join(out))
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
评论记录:
回复评论: