타노스
내코드
from sys import stdin
# 사전순 가장 빠른 것을 출력해야 하기 때문에
# 1은 왼쪽에서 부터 삭제, 0은 오른쪽에서부터 삭제
s = stdin.readline().strip()
count0 = s.count("0")//2
count1 = s.count("1")//2
while count0 > 0 or count1 > 0:
if count1 > 0:
idx1 = s.index("1")
s = list(s)
s[idx1] = ''
s = "".join(s)
count1 -= 1
if count0 > 0:
idx0 = s.rindex("0")
s = list(s)
s[idx0] = ''
s = "".join(s)
count0 -= 1
print("".join(s))
728x90
'Algorithm&CodingTest > Baekjoon' 카테고리의 다른 글
[Beakjoon][7576] 골드5 - 토마토 Python (0) | 2024.10.07 |
---|---|
[Beakjoon][19637] 실버3 - IF문 좀 대신 써줘 Python (0) | 2024.05.05 |
[Baekjoon] [21921] 실버3 - 블로그 Python (1) | 2024.01.31 |
[Baekjoon] [20920] 실버3 영단어 암기는 괴로워 Python (0) | 2024.01.29 |
[Baekjoon] [13305] 실버3 - 주유소 Python (1) | 2024.01.29 |