백준 15237번: Cipher #Python

ColorlessDia·2024년 12월 11일

algorithm/baekjoon

목록 보기
388/807
N, C = map(int, input().split())
frequency = list(map(int, input().split()))

number_history = dict()
length = 0

for number in frequency:

    if number not in number_history:
        number_history[number] = {
            'order': length,
            'count': 1
        }

        length += 1
        continue
    
    number_history[number]['count'] += 1

sorted_history = sorted(number_history.items(), 
                        key=lambda x: (-x[1]['count'], x[1]['order']))

print(' '.join([' '.join([str(k)] * v['count']) for k, v in sorted_history]))

0개의 댓글