CCF 201903-1 python

n=int(input())	#輸入數據個數
nums=[int(x) for x in input().split()]	#輸入n個數據,以空格隔開
ans=[nums[0],nums[-1]]	#由於數據有序排列,將最小值和最大值放入一個列表中
if n%2==0:	#若數據爲偶數個
    temp=(nums[n//2]+nums[n//2-1])/2	#計算中間兩個數的平均值
    ans.append(temp if temp>int(temp) else int(temp))	#如果平均值爲小數則直接添加到列表中,
                                                        #若爲整數,轉換爲int型(否則有.0)
else:
    ans.append(nums[n//2])	#若數據爲奇數個,直接將中位數加入到列表中
[print(x,end=' ')for x in sorted(ans,reverse=True)] #對列表中數值按降序排列,並用空格隔開

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章