Advertisement
amine99

Untitled

Apr 12th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define loop(i,b,e) for(auto i=b;i<=e;i++)
  4.  
  5. const int N=500;
  6. int n,m,x,y,b[N][N],a[N][N];
  7.  
  8. bool isOut(int x,int y) {
  9.     if (x<1 || x>n || y > m || y < 1) return true;
  10.     else return false;
  11. }
  12.  
  13. int main() {
  14.     cin >> n >> m >> x >> y;
  15.     loop(i,1,n+x)
  16.         loop(j,1,m+y)
  17.             cin >> b[i][j];
  18.     loop(i,1,n+x)
  19.         loop(j,1,m+y) {
  20.             if (a[i][j] != 0) continue;
  21.             if (b[i][j] == 0) continue;
  22.             if(isOut(i,j) && !isOut(i-x,j-y))
  23.                 a[i-x][j-y] = b[i][j];
  24.               else if(!isOut(i,j) && isOut(i-x,j-y))
  25.                   a[i][j] = b[i][j];
  26.                else
  27.                  a[i][j] = b[i][j] - a[i-x][j-y];
  28.        }
  29.     loop(i,1,n) {
  30.         loop(j,1,m)
  31.             cout << a[i][j] << " ";
  32.         cout << endl;
  33.     }    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement