[伯俊]1244スイッチのオン/オフ(シルバー4)
白駿(シルバー4)-10867.重複除外ソート(シルバー5)
に答える
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt()+1;
int[] switches = new int[n];
for(int i=1; i<n; i++) {//0번쨰는 없다고 생각하기.
switches[i] = sc.nextInt();
}
int sNum = sc.nextInt();//학생수
for(int i=0; i<sNum; i++) {//학생 성별과 받은 수 넣기
int s = sc.nextInt(); //성별
int number = sc.nextInt();//받은 수
if(s == 1) {//남자라면, 배수
for(int j=number; j< n; j+=number) {
switches[j] = switches[j] == 0? 1:0;
}
}else if(s==2) {//여자라면,받은 수의 대칭들 상태를 바꿔준다.
int left = number-1;
int right = number+1;
while(true) {
if(left<1 || right>=n) break;
if(switches[left]!=switches[right]) break;
left--;
right++;
}
left++;
right--;
for(int k=left; k<=right; k++) {
switches[k] = switches[k] == 0? 1:0;
}
}
}
for(int i=1; i<n; i++) {
System.out.print(switches[i]+" ");
if(i%20 ==0) System.out.println();
}
}
}
Reference
この問題について([伯俊]1244スイッチのオン/オフ(シルバー4)), 我々は、より多くの情報をここで見つけました https://velog.io/@humblechoi/백준-1244.-스위치-켜고-끄기실버4テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol