Advertisement
Josif_tepe

Untitled

Mar 3rd, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main() {
  4.     int n, m;
  5.     cin >> n >> m;
  6.     int mat[n][m];
  7.     for(int i = 0; i < n; i++) {
  8.         for(int j = 0; j < m; j++) {
  9.             cin >> mat[i][j];
  10.         }
  11.     }
  12.     for(int i = 0; i < n; i++) {
  13.         for(int j = 0; j < n; j++) {
  14.             int najmal = 2000000000;
  15.             if(i - 1 >= 0) { // goren sosed
  16.                 najmal = min(najmal, mat[i - 1][j]);
  17.             }
  18.             if(i + 1 < n) { // dolen sosed
  19.                 najmal = min(najmal, mat[i + 1][j]);
  20.             }
  21.             if(j - 1 >= 0) { // lev sosed
  22.                 najmal = min(najmal, mat[i][j - 1]);
  23.             }
  24.             if(j + 1 < m) { // desen sosed
  25.                 najmal = min(najmal, mat[i][j + 1]);
  26.             }
  27.             if(mat[i][j] < najmal) {
  28.                 cout << mat[i][j] << " ";
  29.             }
  30.            
  31.         }
  32.     }
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement