[백준 1439][Python] 뒤집기

봉글렛·2023년 1월 2일

백준

목록 보기
22/55

문제 링크 https://www.acmicpc.net/problem/1439

풀이

line = input()
size = len(line)
count = 0
for i, j in enumerate(line):
    if i == 0:
        continue
    elif j != line[i-1]:
        count += 1
if line[0] == '1':
    if count % 2 != 0:
        table = str.maketrans('10', '01')
        line = line.translate(table)
else:
    if count % 2 == 0:
        table = str.maketrans('10', '01')
        line = line.translate(table)
count = 0
for i in range(size):
    temp = '0'*(size - i)
    while temp in line:
        line = line.replace(temp, '1' * (size - i), 1)
        count += 1

print(count)
profile
어쩌다 개발자 (할 수 있을 때까지!!!!)

0개의 댓글