Skip to content

Instantly share code, notes, and snippets.

@amoshyc
Created December 15, 2014 10:16
Show Gist options
  • Select an option

  • Save amoshyc/78c50d2c0a4d1e8f4d50 to your computer and use it in GitHub Desktop.

Select an option

Save amoshyc/78c50d2c0a4d1e8f4d50 to your computer and use it in GitHub Desktop.
uva541.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int N;
while (scanf("%d", &N)) {
if (N == 0) break;
int row_sum[N];
int col_sum[N];
memset(row_sum, 0, sizeof(row_sum));
memset(col_sum, 0, sizeof(col_sum));
int col, row;
for(col=0; col<N; col++) {
for(row=0; row<N; row++) {
int elem;
scanf("%d", &elem);
row_sum[row] += elem;
col_sum[col] += elem;
}
}
int odd_row_cnt = 0;
int odd_col_cnt = 0;
int row_idx = -1;
int col_idx = -1;
int i;
for(i=0; i<N; i++) {
if (row_sum[i] % 2 == 1) {
odd_row_cnt++;
row_idx = i;
}
if (col_sum[i] % 2 == 1) {
odd_col_cnt++;
col_idx = i;
}
}
if (odd_col_cnt == 0 && odd_row_cnt == 0)
printf("OK\n");
else if (odd_col_cnt == 1 && odd_row_cnt == 1)
printf("Change bit (%d,%d)\n", col_idx+1, row_idx+1);
else
printf("Corrupt\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment