一、题目
二、示例
三、代码
while True:
try:
I = input().split()[1:]
R = map(str, sorted(map(int,set(input().split()[1:]))))
total_Nums = 0
result = ""
for item in R:
temp, counts = '', 0
for i in range(len(I)):
if item in I[i]:
temp += str(i) + ' ' + I[i] + ' '
counts += 1 # 更新符合条件的个数
total_Nums += 2 # 更新总个数
if counts:
temp = item + ' ' + str(counts) + ' ' + temp # 把I中包含R[i]的总个数,索引,以及对应元素存入temp
total_Nums += 2 # 更新总个数
result += temp
print((str(total_Nums) + ' ' + result).rstrip())
except:
break
四、算法说明
这道题目其实难度不大,按部就班的去写,就没问题:
- 用两层循环,尽享遍历
R
和I
,如果R
中的当前元素在I
中,将I
中元素的和元素的索引,存储在temp
中,同时更新符合条件的个数,以及总个数; - 把
I
中包含R[i]
的总个数,索引,以及对应元素存入temp
; - 输出结果,注意去除两头的空格。
胡萝卜
2022年3月13日15:10:58
我不知道将去向何方,但我已在路上! |
---|
时光匆匆,虽未曾谋面,却相遇于斯,实在是莫大的缘分,感谢您的到访 ! |