NeverSayNever's blog

By NeverSayNever, 12 years ago, In English

void init(bool A[MAX][MAX],bool res[MAX][MAX]){

for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
       res[i][j] = A[i][j] = 0;
/**
    memset(res,0,sizeof(res));
    memset(A,0,sizeof(A));
**/
for(int i=0;i<n;i++)
    A[P[i]][i] = 1,res[i][i] = 1;

}

Here is the code snippet. If i used the commented part instead of two loops it fails and produce a weird output.

here is the full code link and problem link. http://ideone.com/cdsWYE http://www.spoj.com/problems/PDECODE/

Please if anyone can help then suggest me a valid reason for this.

  • Vote: I like it
  • +15
  • Vote: I do not like it

»
12 years ago, hide # |
 
Vote: I like it +29 Vote: I do not like it
»
12 years ago, hide # |
Rev. 3  
Vote: I like it +18 Vote: I do not like it

replace

void init(bool A[MAX][MAX],bool res[MAX][MAX]){

with

void init(bool (&A)[MAX][MAX],bool (&res)[MAX][MAX]){