541 - Error Correction ( uva solution )


541 - Error Correction



import java.util.Scanner;

public class Main{   //this is mandatory that in the class name "Main" "M" must be capital letter


public static void main(String [] args){
Scanner sc=new Scanner(System.in);
int n;

while(sc.hasNext()){
n=sc.nextInt();

if(n==0) break;
int a[][] =new int[300][300];
int r,c,e,f,in1=0,in2=0;
r=c=e=f=0;
for(int i=0;i<n;i++){

for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
}
int i,j;
for( i=0;i<n;i++){
r=0;

for( j=0;j<n;j++){
r+=a[i][j];

}
if(r%2!=0){
e++;
in1=i+1;


}


}


for( i=0;i<n;i++){
c=0;

for( j=0;j<n;j++){
c+=a[j][i];

}
if(c%2!=0){
f++;
in2=i+1;


}


}
if(f==0&&e==0)
System.out.println("OK");
else if(f==1&&e==1)
System.out.println("Change bit ("+in1+","+in2+")");
else
System.out.println("Corrupt");





}
}

}

SHARE

Amit Ghosh

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment