- Practice
- Algorithms
- Implementation
- Cavity Map
- Discussions

# Cavity Map

# Cavity Map

Michael123 + 0 comments no need to read the input as string . read it as int using "scanf("%1d",your array[i)[j]);" ...read only a single digit at a time

sayantanmaiti + 0 comments Why does Test Case #2 have spaces in the input grid? Although submitting the code that works for the Test Case #1 (one without the spaces) works fine for everything else, and gives the full 30 points,

I kind-of wasted my time because my code was reading the spaces in the grid rather than the number itself.

_CAAI + 0 comments Instead of using two arrays, compare the center matrix (formed excluding boundary values) while printing the matrix..! ;)

`int n,i,j; scanf("%d",&n); int a[n][n]; for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%1d",&a[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if( (i>=1)&&(i<n-1) && (j>=1)&&(j<n-1) ) { if( (a[i][j] > a[i-1][j]) && (a[i][j] > a[i][j+1]) && (a[i][j] > a[i+1][j]) && (a[i][j] > a[i][j-1]) ) printf("X"); else printf("%d",a[i][j]); } else printf("%d",a[i][j]); } printf("\n"); }`

cheesus + 0 comments the conditions are:

1) is right or left of the current value a value that is greater or equals

2) is above or below of the current value a value that is greater or equals

3) is it in the first or last row or is it the first or last number

if so it cant be a cavity

I just created an inverse of a 2 dimensional array and checked those conditions for both matrices. Even its O(N*N) it doesnt needs a 1/10 of a second

selftaught91 + 0 comments Read your input as string and not as integers then the problem can be solved

Sort 582 Discussions, By:

Please Login in order to post a comment