Updated:

๐Ÿ–๏ธย solution

import sys
from collections import Counter

"""
[์‹œ๊ฐ„]
1) 23:50 ~ 24:03

[์š”์•ฝ]
1) ์ˆ˜์˜ ๊ฐ ์ž๋ฆฌ์ˆ˜๋ฅผ ๋‚ด๋ฆผ์ฐจ์ˆœ
 - 2143: 4321
[์ „๋žต]
1) ์ž…๋ ฅ ๋ฐ›๋Š” ์ˆซ์ž๋ฅผ split์œผ๋กœ ์ž˜๋ผ์„œ ๋‹ค์‹œ sort ํ•ด์•ผ์ง€
    - split, Counter, sort ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด ๋  ๋“ฏ
"""
n = list(sys.stdin.readline().rstrip())
count = Counter(n)
tmp_result = sorted(count.elements(), reverse=True)
print(int(''.join(tmp_result)))

๐Ÿ’กย idea

  • 1) ์ž…๋ ฅ๋œ ์ˆซ์ž๋ฅผ ๋ฌธ์ž์—ด๋กœ ๊ฐ„์ฃผ
    • ๋ฌธ์ž์—ด์„ ๋ฆฌ์ŠคํŠธ์— ๋‹ด์•„ ๊ฐœ๋ณ„ ์›์†Œ๋กœ ์ฐข์–ด์ง€๊ฒŒ ๋งŒ๋“ค๊ธฐ
  • 2) collection.Counter๋ฅผ ์ด์šฉํ•ด ๊ฐœ์ˆ˜ ์„ธ๊ธฐ
    • Counter ๊ฐ์ฒด์— sorted์™€ elements ๋ฉ”์„œ๋“œ ์ ์šฉํ•ด์„œ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ๋ฌธ์ž์—ด์„ ๋งŒ๋“ค๊ธฐ
    • ๋งŒ๋“ค์–ด์ง„ ๋‚ด๋ฆผ์ฐจ์ˆœ ๋ฌธ์ž์—ด์„ ๋‹ค์‹œ ์ˆซ์ž๋กœ ๋ณ€ํ™˜

Leave a comment