问题描述
给定
n
个正整数,
找出它们中出现次数最多的数。
如果这样的数有多个,
请输出其中最小的
一个。
输入格式
输入的第一行只有一个正整数
n(1
≤
n
≤
10)
,表示数字的个数。
输入的第二行有
n
个整数
s1, s2, ... sn (1
≤
si
≤
1000, 1
≤
i
≤
n).
相邻的数用空格分隔。
输出格式
输出这
n
个次数中出现次数最多的数。如果这样的数有多个,输出其中最小的一一个。
样例输入
6
10 1 10 20 30 20
样例输出
10
代码
from collections import Counter
num = int(input("
请输入数字个数
"))
#python
里这一这一步好像没用,
完全为了应付题
目
a=input().split()
#
输入数字
num_count = Counter(a)
#
统计
# print(num_count)
#
删了‘
#
’可以帮你看看过程
num_count
=
sorted(num_count.items(),reverse
=
True,key=lambda
num_count:num_count[1])
#
排序
# print(num_count)
#
删了‘
#
’可以帮你看看过程
print(num_count[0][0])