PS/Python
[Python] 백준(BOJ) 1244번: 스위치 켜고 끄기
yoo.o
2021. 11. 11. 01:59
반응형
문제
1244번: 스위치 켜고 끄기
첫째 줄에는 스위치 개수가 주어진다. 스위치 개수는 100 이하인 양의 정수이다. 둘째 줄에는 각 스위치의 상태가 주어진다. 켜져 있으면 1, 꺼져있으면 0이라고 표시하고 사이에 빈칸이 하나씩
www.acmicpc.net
풀이
문제의 끝부분을 안읽어서 출력형식 오류를 두번이나..
import sys
N = int(sys.stdin.readline())
switch_list = list(map(int, sys.stdin.readline().split(" ")))
switch_list.insert(0, 0)
def toggle(i):
switch_list[i] = abs(switch_list[i] - 1)
def boys(int):
current = int
while current <= N:
toggle(current)
current += int
def girls(int):
total = min(N + 1 - int, int)
toggle(int)
for i in range(total):
if switch_list[int + i] == switch_list[int - i]:
toggle(int + i)
toggle(int - i)
else:
break
students = int(sys.stdin.readline())
for _ in range(students):
s, num = map(int, sys.stdin.readline().split(" "))
if s == 1:
boys(num)
else:
girls(num)
for k in range(0, N, 20):
for switch in switch_list[1+k:21+k]:
print(switch, end=" ")
print()
반응형