朱色虫居
Pages
Home
Featured Posts
2006/10/11
541-Error Correction
/*
"Error Correction"
Level:1.5
Date:2006/10/10
技巧: Corrupt:有兩列or兩行以上 有error
只有一列 or 只有一行 有error
Change bit:只有一列 and 只有一行 有error
OK:沒有任何error
*/
#include
#define SIZE 100
main(){
int matrix[SIZE][SIZE]={0};
int i=0,j=0,n=0,row=0,column=0,sum=0;
BEGIN:
while(scanf("%d",&n)==1 && n!=0){
column = row = 0;
for(i=0;i < n;i++) for(j=0;j < n;j++) scanf("%d",&matrix[i][j]); for(i=0;i < n;i++){ sum=0; for(j=0;j < n;j++){ sum += matrix[i][j]; } if(sum%2 != 0 && row == 0) row = i+1; /* 記錄第幾列有error */ else if(sum%2 !=0 && row > 0){
printf("Corrupt\n");
goto BEGIN;
}
}
for(j=0;j < n;j++){ sum = 0; for(i=0;i < n;i++){ sum += matrix[i][j]; } if(sum%2 != 0 && column == 0) column = j+1; /* 記錄第幾行有error */ else if(sum%2 !=0 && column >0){
printf("Corrupt\n");
goto BEGIN;
}
}
if(row > 0){
if(column > 0)
printf("Change bit (%d,%d)\n",row,column);
else
printf("Corrupt\n");
goto BEGIN;
}
if(column > 0)
printf("Corrupt\n");
else
printf("OK\n");
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment