-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1474.py
51 lines (40 loc) · 1.15 KB
/
1474.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
from collections import deque
input = sys.stdin.readline
def solution() -> str:
total_underbar = m
for idx, word in enumerate(word_list):
total_underbar -= len(word)
default_num = total_underbar // (n - 1)
num_addition = total_underbar % (n - 1)
underbar_list = [default_num] * (n - 1)
pos_uppers = []
pos_lowers = deque()
for pos in range(1, n):
if is_upper(word_list[pos][0]):
pos_uppers.append(pos)
else:
pos_lowers.append(pos)
k = 0
while k < num_addition:
if len(pos_lowers):
pos_add = pos_lowers.popleft()
else:
pos_add = pos_uppers.pop()
underbar_list[pos_add-1] += 1
k += 1
res = [word_list[0]]
for idx, num in enumerate(underbar_list, start=1):
res.append(num * '_')
res.append(word_list[idx])
return ''.join(res)
def is_upper(c: chr) -> bool:
if 65 <= ord(c) < 97:
return True
else:
return False
if __name__ == '__main__':
n, m = map(int, input().split())
word_list = [input().rstrip() for i in range(n)]
sol = solution()
print(sol)