UVA – 541 – Error Correction

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int N = -1, a[][], r[], c[];
        while ((N = in.nextInt()) != 0) {
            a = new int[N + 2][N + 2];
            r = new int[N + 2];
            c = new int[N + 2];

            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    // a[i]= (b[i][j]=in.nextInt()) + a[i][j];
                    a[i][j] = in.nextInt();
                    r[i] += a[i][j];
                    c[j] += a[i][j];
                }
            }

            int badC = 0, badR = 0, badi = 0, badj = 0;
            for (int i = 1; i <= N; i++) {
                if (c[i] % 2 != 0) {
                    badC++;
                    badi = i;
                }
                if (r[i] % 2 != 0) {
                    badR++;
                    badj = i;
                }
            }

            if (badC == badR) {
                if (badC == 0)
                    System.out.printf("OK\n");
                if (badC == 1)
                    System.out.printf("Change bit (%d,%d)\n", badj, badi);
            } else {
                System.out.println("Corrupt");
            }
        }
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: