讨论 / python2题解
SamsonRuan 2018-11-27 17:41:48
点我顶贴 收藏 删除
from __future__ import print_function

#获取输入

container = []

number = int(raw_input())

str = raw_input()

container = str.split(" ")

for i in range(len(container)):

container[i] = int(container[i])

#排序

for j in range(number-1,0,-1):

for i in range(j):

if container[i] >= container[i+1]:

max = container[i]

container[i] = container[i+1]

container[i+1] = max

#去重

new_container = []

for i in range(number-1):

if i < number-2:

if container[i] not in container[i+1:]:

new_container.append(container[i])

else:

if container[i] == container[i+1]:

new_container.append(container[i])

else:

new_container.append(container[i])

new_container.append(container[i+1])

#输出

print(len(new_container))

for i in range(len(new_container)):

if i != len(new_container)-1:

print(new_container[i],end = ' ')

else:

print(new_container[i],end = "")

查看更多回复
提交回复