Advertisement
Josif_tepe

Untitled

Mar 3rd, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 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.     int x, y;
  13.     cin >> x >> y;
  14.     // sosedot gore od ova pole (x - 1, y)
  15.     if(x - 1 >= 0) {
  16.         cout << "Goren sosed: " << mat[x - 1][y] << endl;
  17.     }
  18.    
  19.     // sosedot dole od ova pole (x + 1, y)
  20.     if(x + 1 < n) {
  21.         cout << "Dolen sosed: " << mat[x + 1][y] << endl;
  22.     }
  23.    
  24.     //sosedot levo od ova pole (x, y - 1)
  25.     if(y - 1 >= 0) {
  26.         cout << "Lev sosed: " << mat[x][y - 1] << endl;
  27.     }
  28.    
  29.     // sosedot desno od ova pole (x, y + 1)
  30.     if(y + 1 < m) {
  31.         cout << "Desen sosed: " << mat[x][y + 1] << endl;
  32.     }
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement