코드와이
[BAEKJOON] 1244. 스위치 켜고 끄기 본문
문제링크
1244번: 스위치 켜고 끄기
첫째 줄에는 스위치 개수가 주어진다. 스위치 개수는 100 이하인 양의 정수이다. 둘째 줄에는 각 스위치의 상태가 주어진다. 켜져 있으면 1, 꺼져있으면 0이라고 표시하고 사이에 빈칸이 하나씩
www.acmicpc.net
package acmicpc;
import java.util.Scanner;
public class 스위치켜고끄기 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
int[] arr = new int[T+1];
arr[0] = -1;
for (int i = 1 ; i < T+1 ; i++) {
arr[i] = sc.nextInt();
}
int n = sc.nextInt();
for( int l = 0 ; l < n ; l++) {
int a = sc.nextInt();
int m = sc.nextInt();
if ( a == 1) {
int t = m;
while (m < T + 1) {
arr[m] = (arr[m] + 1) % 2;
m += t;
}
}
else {
int w2 = m;
while (true) {
if ( m - 1 > 0 && w2 + 1 <= T && arr[m - 1] == arr[w2 + 1]) {
m -= 1;
w2 += 1;
} else break;
}
for(int i = m ; i <= w2 ; i++) {
arr[i] = (arr[i] + 1) % 2;
}
}
}
for (int i = 1 ; i <= T ; i++) {
System.out.print(arr[i] + " ");
if (i % 20 == 0) System.out.println();
}
}
}
'acmicpc' 카테고리의 다른 글
[BAEKJOON] 2563. 색종이 (0) | 2021.02.10 |
---|---|
[BAEKJOON] 1158. 요세푸스 문제 (0) | 2021.02.08 |
[BAEKJOON] 2164. 카드2 (0) | 2021.02.06 |
[BAEKJOON] 1057. 토너먼트 (0) | 2021.02.06 |
[BAEKJOON] 1051. 숫자 정사각형 (0) | 2021.02.06 |