def check_list(ls1):
even_number = 0
odd_number = 0
for element in ls1:
if element < 0:
return 'ERROR'
elif element % 2 == 0:
even_number += 1
elif element % 2 != 0:
odd_number += 1
if even_number != odd_number:
return 'ERROR'
# print(check_list(ls_input))
def change_list(ls2):
ls_even = []
ls2.sort()
for element in ls2:
if element % 2 == 0:
ls_even.append(element)
ls_even.append(0)
for element in ls2:
if element % 2 != 0:
ls_even.insert(ls_even.index(0), element)
ls_even.remove(0)
return ls_even
if __name__ == '__main__':
ls_input = list(map(int, input().split()))
if check_list(ls_input):
print('ERROR')
else:
print(change_list(ls_input))
奇偶插入(列表)python
最新推荐文章于 2023-07-17 15:28:36 发布