Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Input:
- 2 2
- 3 -1
- 2 4
- Output:
- -1 2
- Explanation:
- -1 is smaller than 2, 3 & 4
- 2 is smaller than 3 & 4
- Solution:
- */
- #include <stdio.h>
- int main(){
- int n,m,i,j,mat[100][100],max;
- scanf("%d%d", &n, &m);
- for(i=0;i<n;++i)
- for(j=0;j<m;++j)
- scanf("%d", &mat[i][j]);
- printf("\n");
- for(i=0;i<n;++i){
- int x1,x2,x3,x4;
- for(j=0;j<m;++j){
- if((i-1) >= 0)
- x1 = mat[i-1][j];
- else x1=9999;
- if((i+1) < m)
- x2 = mat[i+1][j];
- else x2=9999;
- if((j-1) >= 0)
- x3 = mat[i][j-1];
- else x3=9999;
- if((j+1) < n)
- x4 = mat[i][j+1];
- else x4=9999;
- //printf("%d %d %d %d - %d\n", x1,x2,x3,x4,mat[i][j]);
- if(mat[i][j]<x1 && mat[i][j]<x2 && mat[i][j]<x3 && mat[i][j]<x4)
- printf("%d ", mat[i][j]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement