https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV19AcoKI9sCFAZN
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
1이 나왔을 경우 그 뒤를 모두 반대숫자로 바꾸는 형식으로...숫자를 뒤집는 방식으로 풀었다
T = int(input())
for tc in range(1,T+1):
memory = list(input())
cnt = 0
while True:
for i in range(len(memory)):
if memory[i] == '1':
for j in range(i,len(memory)):
if memory[j] == '1':
memory[j] = '0'
else:
memory[j] = '1'
cnt += 1
if memory.count(1) == 0:
break
print(f'#{tc} {cnt}')
다른사람의 간결한 풀이
T = int(input())
for tc in range(1, T + 1):
goal = list(map(int, input()))
ans = 0
prev = 0
for cur in goal:
if prev != cur:
prev = cur
ans += 1
print(f'#{tc} {ans}')
'swea' 카테고리의 다른 글
2805. 농작물 수확하기 (0) | 2023.08.27 |
---|---|
1926. 간단한 369게임 (0) | 2023.08.27 |
7087. 문제 제목 붙이기 (0) | 2023.08.25 |
4613. 러시아 국기 같은 깃발 (0) | 2023.08.24 |
16811. 당근 포장하기 (0) | 2023.08.22 |