合并两个升序列表为一个有序列表
类型:程序题

题目说明

科技小组分 2 个小队搜集到西红柿生长的数据信息。2 个小队将数据进行了从小到大排序:a = [1,3,4,6,7,13,17,21],b = [2,5,6,8,10,12,14,16,18],请明明将这 2 个小队的数据进行合并,生成为一个从小到大有序的列表。

输入:

1,3,4,6,7,13,17,21
2,5,6,8,10,12,14,16,18

输出:

[1,2,3,4,5,6,6,7,8,10,12,13,14,16,17,18,21]

请帮明明编写程序实现上述功能,或补全代码。

x = input()
s = x.split(',')
a=[]
for i in range(    ①     ):
    a.append(int(s[i]))
y = input()
s = y.   ②
b=[]
for i in range(len(s)):
    b.append(int(s[i]))
ret = []
i = j = 0
while len(a) >= i + 1 and     ③   :
    if a[i] <= b[j]:
        ④
        i += 1
    else:
        ret.append(b[j])
        j += 1
if len(a) > i:
    ret += a[i:]
if len(b) > j:
    ⑤
print(ret)

评分标准

  1. len(s) 或等效答案;(3分)

  2. split(',') 或等效答案;(3分)

  3. len(b) >= j + 1 或等效答案;(3分)

  4. ret.append(a[i]) 或等效答案;(3分)

  5. ret += b[j:] 或等效答案。(4分)

代码编辑器 加载中...
留空使用题目默认限制
{{resultStatus.text}}
正在加载运行记录...
乐编题库AI助手
人工客服
微信扫码联系客服
历史对话
{{ s.title || '未命名对话' }}
{{ s.created_at }}
暂无历史对话
我能帮助你什么?