#42817: python


suyueh (suyueh)

學校 : 不指定學校
編號 : 272111
來源 : [101.12.160.127]
最後登入時間 :
2024-11-21 22:51:47
b374. [福州19中]众数 | From: [125.229.229.84] | 發表日期 : 2024-10-05 14:12

from collections import defaultdict

def find_modes(numbers):
    freq = defaultdict(int)
    
    for num in numbers:
        freq[num] += 1
    
    max_freq = max(freq.values())
    
    result = []
    for num, count in freq.items():
        if count == max_freq:
            result.append((num, count))
    
    return result

n = int(input())
numbers = list(map(int, input().split()))

modes = find_modes(numbers)

for mode, count in sorted(modes):
    print(mode, count)

 
ZeroJudge Forum