Advertisement
Vprento

Соседи

Nov 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main ()
  4. {
  5.     int m,n;    
  6.     scanf("%d%d",&m,&n);
  7.     int mat[m][n];
  8.    
  9.     for(int i=0;i<m;i++) {
  10.         for(int j=0;j<n;j++)
  11.             scanf("%d",&mat[i][j]);
  12.     }
  13.    
  14.     for(int i=0;i<m;i++) {
  15.         for(int j=0;j<n;j++) {
  16.             int s=0;
  17.  
  18.             if((i-1) >= 0 && mat[i-1][j] > mat[i][j])
  19.                 s += mat[i-1][j];            
  20.             if((i+1) < m && mat[i+1][j] > mat[i][j])
  21.                 s += mat[i+1][j];      
  22.             if((j-1) >= 0 && mat[i][j-1] > mat[i][j])
  23.                 s += mat[i][j-1];
  24.             if((j+1) < n && mat[i][j+1] > mat[i][j])
  25.                 s += mat[i][j+1];
  26.              
  27.             printf("%d ",s);          
  28.         }
  29.         printf("\n");
  30.     }  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement