Advertisement
Josif_tepe

Untitled

Feb 26th, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int a,b;
  9.     cin>>a>>b;
  10.     int m[a][b];
  11.     int razlika[a*b];
  12.     int ri=0;
  13.     for(int i=0;i<a;i++)
  14.     {
  15.         for(int j=0;j<b;j++)
  16.         {
  17.             cin>>m[i][j];
  18.         }
  19.     }
  20.     for(int i=0;i<a;i++)
  21.     {
  22.         for(int j=0;j<b;j++)
  23.         {
  24.             int najmal=2e9;
  25.             if(i-1>=0)
  26.             {
  27.                 if(najmal>m[i-1][j])
  28.                 {
  29.                     najmal=m[i-1][j];
  30.                 }
  31.  
  32.  
  33.             }
  34.             if((i+1)<a)
  35.             {
  36.                 if(najmal>m[i+1][j])
  37.                 {
  38.                     najmal=m[i+1][j];
  39.                 }
  40.  
  41.  
  42.             }
  43.             if(j-1>=0)
  44.             {
  45.                 if(najmal>m[i][j-1])
  46.                 {
  47.                     najmal=m[i][j-1];
  48.                 }
  49.  
  50.  
  51.             }
  52.             if(j+1<b)
  53.             {
  54.                 if(najmal>m[i][j+1])
  55.                 {
  56.                     najmal=m[i][j+1];
  57.                 }
  58.             }
  59.                 if(najmal>m[i][j])
  60.                             {
  61.                                 razlika[ri]=najmal-m[i][j];
  62.                                 ri++;
  63.                             }
  64.  
  65.                         }
  66.  
  67.                     }
  68.                     sort(razlika,razlika+ri);
  69.                     for(int i=ri-1;i>=0;i--)
  70.                     {
  71.                         cout<<razlika[i]<<" ";
  72.                     }
  73.                     return 0;
  74.                 }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement