on
[JAVA] 1037번 오류교정
[JAVA] 1037번 오류교정
문제
http://jungol.co.kr/bbs/board.php?bo_table=pbank≀_id=316&sca;=99
풀이
단순 구현문제로, 행과 열을 따로 검사하여 1의 개수가 짝수인지 홀수인지를 판별하는 과정을 거친다.
검사하는 과정에서 홀수번째의 1이 나오면 해당 좌표를 저장한다.
그 후, 홀짝의 개수에 따라 분기를 나눠 값을 출력한다.
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class 오류교정 { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; int N = Integer.parseInt(br.readLine()); int arr[][] = new int[N][N]; int count = 0; int check1 = 0; int check2 = 0; int pos1 = 0; int pos2 = 0; for (int i = 0; i < N; i++) { st = new StringTokenizer(br.readLine()); for (int j = 0; j < N; j++) { arr[i][j] = Integer.parseInt(st.nextToken()); } } for (int i = 0; i < arr.length; i++) { count = 0; for (int j = 0; j < arr.length; j++) if (arr[i][j] == 1) count++; if (count % 2 != 0) { check1++; pos1 = i; } } for (int i = 0; i < arr.length; i++) { count = 0; for (int j = 0; j < arr.length; j++) if (arr[j][i] == 1) count++; if (count % 2 != 0) { check2++; pos2 = i; } } if (check1 == 0 && check2 == 0) System.out.println("OK"); else if (check1 == 1 && check2 == 1) System.out.println("Change bit (" + (pos1+1) + "," + (pos2+1) + ")"); else System.out.println("Corrupt"); } }
from http://pekahblog.tistory.com/154 by ccl(S) rewrite - 2021-09-23 11:01:35