๐ฃ ZOAC
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
Python
92ms
31256KB
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
c = input()
t = ''
visited = [False] * len(c) # ๋ฌธ์์ด ๋ฐฉ๋ฌธ ์ฒ๋ฆฌ
while len(t) < len(c):
max_score = 'Z' * 100 # ์ต๋ 100๊ฐ๊น์ง
max_target = 0
now, t = '', ''
for i in range(len(c)):
if visited[i]:
now += c[i]
continue
# ๋ง์ฝ ๋ฏธ๋ฐฉ๋ฌธ ์ํ๋ฒณ์ด๋ฉด ํด๋น ์ํ๋ฒณ ์ถ๊ฐํ๋ ๊ฒฝ์ฐ๊ฐ ์ต์ ์ธ์ง ํ๋จ
# max_score ๊ณ์ฐ
if not visited[i]:
tmp = now + c[i]
for j in range(i + 1, len(c)):
if visited[j]:
tmp += c[j]
if tmp < max_score: # ์ํ๋ฒณ ์์ ๊ณ์ฐ
max_score = tmp
max_target = i
visited[max_target] = True
for i in range(len(c)):
if visited[i]:
t += c[i]
print(t)
This post is licensed under CC BY 4.0 by the author.