n=input() n=eval(n) a=input().split() a=[eval(item) for item in a] a.sort() count_small=0 count_big=0 if n%2==1: mid=int(n//2) for item in a[:mid]: if item!=a[mid]: count_small+=1 for item in a[mid+1:]: if item != a[mid]: count_big += 1 if count_small==count_big: print(a[mid]) else: print(-1) else:#偶数数组 mid1=int(n/2-1) mid2=int(n/2) if a[mid1]!=a[mid2]: print(-1) else: for item in a[:mid1]: if item!=a[mid1]: count_small+=1 for item in a[mid2:]: if item!=a[mid2]: count_big+=1 if count_small==count_big: print(a[mid1]) else: print(-1)
CCF 2016-12-1 中间数 PYTHON
最新推荐文章于 2024-04-26 16:41:33 发布