Algorithms and Data Structures/Coding Practices

Kattis Sort

brightlightkim 2022. 7. 20. 14:41

n, c = map(int, input().split())
nums = list(map(int, input().split()))
dict = {}
for i in range(len(nums)):
    if nums[i] in dict:
        dict[nums[i]] += 1
    else:
        dict[nums[i]] = 1
indexMap = {}
for num in dict:
    if dict[num] in indexMap:
        indexMap[dict[num]].append(num)
    else:
        indexMap[dict[num]] = [num]

for freq in sorted(indexMap, reverse=True):
    for num in indexMap[freq]:
        for _ in range(freq):
            print(num, end=' ')

'Algorithms and Data Structures > Coding Practices' 카테고리의 다른 글

Kattis Average Character  (0) 2022.07.20
AlgoExpert Smallest Difference  (0) 2022.07.20
Kattis Skru op!  (0) 2022.07.19
AlgoExpert Three Number Sum  (0) 2022.07.19
AlgoExpert Generate Document  (0) 2022.07.19