something going wrong
1 2 3 4
|
if ((b[x][y]!=-1) && ((y-1>=0 && b[x][y-1]==b[x][y]) || (x-1>=0 && b[x-1][y]==b[x][y]) || (x-1>=0 && y-1>=0 && b[x-1][y-1]==b[x][y]) || (x+1<n && y-1>=0 && b[x+1][y-1]==b[x][y]) || (y+1<m && x-1>=0 && b[x-1][y+1]) || (y+1<m && x+1<n && b[x+1][y+1]==b[x][y]) || (y+1<m && b[x][y+1]==b[x][y]) || (x+1<n && b[x+1][y]==b[x][y])))
{
cout<<"YES"<<endl;
}
|
this code should output "YES" if there is an adjacent integer in the array (b[100][100]) that is equal to it.
but when i put the input:
its outputting YES 4 times but the 1 has no adjacent integers which are equal to it
thanks
Last edited on
the input is the array
its outputting YES 4 times but the 1 has no adjacent integers which are equal to it |
Then, obviously your logic is wrong. Perhaps breaking it down into smaller pieces will reveal where.
Last edited on
Topic archived. No new replies allowed.