NC25070. [USACO 2007 Ope l]Popularity
描述
输入描述
Line 1: A single integer: N
Lines 2..N+1: Line i contains a single integer that is the ounces of milk given by cow i.
输出描述
Line 1: The number that appears most often in the input list
示例1
输入:
5 512 532 532 585 599
输出:
532
说明:
Five cows, each giving 512-599 ounces of milk.Python3 解法, 执行用时: 71ms, 内存消耗: 5216K, 提交时间: 2023-08-15 09:05:57
from collections import defaultdict ans = 0 m = defaultdict(int) for i in range(int(input())): c = int(input()) m[c] += 1 if m[c] > m[ans]: ans = c print(ans)
Python3 解法, 执行用时: 56ms, 内存消耗: 5212K, 提交时间: 2023-08-15 07:52:17
from collections import defaultdict ans = 0 num = 0 m = defaultdict(int) for i in range(int(input())): c = int(input()) m[c] += 1 if m[c] > num: num = m[c] ans = c print(ans)