From 5ae4c89285528417d4850637aaf2b4f76e0465d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8A=B9=EB=AF=BC?= Date: Thu, 12 Oct 2023 14:17:26 +0900 Subject: [PATCH] Update 2023.10.12 --- Silver_I/1474.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Silver_I/1474.py diff --git a/Silver_I/1474.py b/Silver_I/1474.py new file mode 100644 index 0000000..aac72a6 --- /dev/null +++ b/Silver_I/1474.py @@ -0,0 +1,45 @@ +# 밑 줄 +import sys +input = sys.stdin.readline + +n, m = map(int, input().split()) + +strings = [] +total_length = 0 + +for i in range(n): + temp_string = input().strip() + strings.append(temp_string) + total_length += len(temp_string) + +result_string = "" + +# m 길이만큼 채우기 위해 필요한 밑줄 수 +needed_line = m - total_length + +# 문자열 사이를 채울 최소 라인 수 +one_line = needed_line // (n - 1) + +# 문자열 사이를 최소 라인으로 채우고 남은 라인 수 (더 채워야 할 라인) +add_line = needed_line % (n - 1) + +count = n - 1 + +for i in range(n): + result_string += strings[i] + + if count > 0: + result_string += "_" * one_line + count -= 1 + + if add_line > 0 and i < n - 1 and strings[i+1] > "_": + result_string += "_" + add_line -= 1 + + if add_line > 0 and add_line >= n - i - 1: + result_string += "_" + add_line -= 1 + + + +print(result_string) \ No newline at end of file