====== 숫자의 신 ====== ===== 풀이 ===== * [[ps:problems:boj:16496]]의 응용 문제이다. * [[ps:problems:boj:16496]] 에서의 핵심은, 숫자들을 늘어놓아서 가장 큰 수를 만들기 위해서는 숫자들을 문자열로 처리해서 정렬하되 비교함수를 x+y """Solution code for "BOJ 1422. 숫자의 신". - Problem link: https://www.acmicpc.net/problem/1422 - Solution link: http://www.teferi.net/ps/problems/boj/1422 """ import functools def main(): K, N = [int(x) for x in input().split()] nums = [input() for _ in range(K)] num_to_repeat = max(nums, key=int) sorted_nums = sorted( nums + [num_to_repeat] * (N - K), key=functools.cmp_to_key(lambda x, y: -1 if (x + y) > (y + x) else 1)) answer = ''.join(sorted_nums) print(answer) if __name__ == '__main__': main() {{tag>BOJ ps:problems:boj:플래티넘_5}}