简答题 偏难
#4447

科技小组分2个小队搜集到西红柿生长的数据信息。2个小队将数据进行了从小到大排序: a = [1,3,4,6,7,13,17,21], b = [2,5,6,8,…

科技小组分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)):

   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)

未登录也能判分,登录后才会记录
答案与解析
正确答案:<p>参考答案:</p><pre class="brush:python;toolbar:false">x = input() s = x.split(',') a=[] for i in range(len(s)):    a.append(int(s[i])) y = input() s = y.split(',') b=[] for i in range(len(s)):    append(int(s[i])) ret = [] i, j = 0, 0 while len(a) &gt;= i + 1 and len(b) &gt;= j + 1:    if a[i] &lt;= b[j]:       ret.append(a[i])       i += 1    else:       ret.append(b[j])       j += 1 if len(a) &gt; i:    ret += a[i:] if len(b) &gt; j:    ret += b[j:] print(ret)</pre><p><br/></p>
解析

评分参考:

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

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

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

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

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