Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. /*
  2. Input:
  3. 2 2
  4. 3 -1
  5. 2 4
  6.  
  7. Output:
  8. -1 2
  9.  
  10. Explanation:
  11. -1 is smaller than 2, 3 & 4
  12. 2 is smaller than 3 & 4
  13.  
  14. Solution:
  15. */
  16. #include <stdio.h>
  17. int main(){
  18.     int n,m,i,j,mat[100][100],max;
  19.     scanf("%d%d", &n, &m);
  20.         for(i=0;i<n;++i)
  21.            for(j=0;j<m;++j)
  22.             scanf("%d", &mat[i][j]);
  23.         printf("\n");
  24.     for(i=0;i<n;++i){
  25.             int x1,x2,x3,x4;
  26.            for(j=0;j<m;++j){
  27.                 if((i-1) >= 0)
  28.                x1 = mat[i-1][j];
  29.                else x1=9999;
  30.             if((i+1) < m)
  31.                 x2 = mat[i+1][j];
  32.             else x2=9999;
  33.             if((j-1) >= 0)
  34.                 x3 = mat[i][j-1];
  35.             else x3=9999;
  36.             if((j+1) < n)
  37.                 x4 = mat[i][j+1];
  38.             else x4=9999;
  39.      //printf("%d %d %d %d  - %d\n", x1,x2,x3,x4,mat[i][j]);
  40.      if(mat[i][j]<x1 && mat[i][j]<x2 && mat[i][j]<x3 && mat[i][j]<x4)
  41.            printf("%d ", mat[i][j]);
  42.            }
  43.     }
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement