Advertisement
Josif_tepe

Untitled

Mar 3rd, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 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 x1, y1;
  13.     cin >> x1 >> y1;
  14.    
  15.     int x2, y2;
  16.     cin >> x2 >> y2;
  17.    
  18.     int zbir1 = 0;
  19.     if(x1 - 1 >= 0) { // postoi gorniot sosed
  20.         zbir1 += mat[x1 - 1][y1];
  21.     }
  22.     if(x1 + 1 < n) { // postoi dolniot sosed
  23.         zbir1 += mat[x1 + 1][y1];
  24.     }
  25.     if(y1 - 1 >= 0) { // postoi leviot sosed
  26.         zbir1 += mat[x1][y1 - 1];
  27.     }
  28.     if(y1 + 1 < m)  { // postoi desniot sosed
  29.         zbir1 += mat[x1][y1 + 1];
  30.     }
  31.    
  32.     int zbir2 = 0;
  33.     if(x2 - 1 >= 0) { // postoi gorniot sosed
  34.         zbir2 += mat[x2 - 1][y2];
  35.     }
  36.     if(x2 + 1 < n) { // postoi dolniot sosed
  37.         zbir2 += mat[x2 + 1][y2];
  38.     }
  39.     if(y2 - 1 >= 0) { // postoi leviot sosed
  40.         zbir2 += mat[x2][y2 - 1];
  41.     }
  42.     if(y2 + 1 < m) {
  43.         zbir2 += mat[x2][y2 + 1];
  44.     }
  45.    
  46.     if(zbir1 > zbir2) {
  47.         cout << "Poleto so indeks: (" << x1 << "," << y1 << ") ima pogolem zbir na sosedi" << endl;
  48.     }
  49.     else {
  50.         cout << "Poleto so indeks: (" << x2 << "," << y2 << ") ima pogolem zbir na sosedi" << endl;
  51.     }
  52.     return 0;
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement