Advertisement
STANAANDREY

fill rec

Oct 7th, 2019
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. int a[100][100];
  5.  
  6. inline void Fill(int i, int j)
  7. {
  8.     a[i][j] = 1;
  9.     if(a[i+1][j]== -1)
  10.         Fill(i + 1, j);
  11.     if(a[i-1][j]== -1)
  12.         Fill(i - 1, j);
  13.     if(a[i][j+1]== -1)
  14.         Fill(i, j + 1);
  15.     if(a[i][j-1]== -1)
  16.         Fill(i, j - 1);
  17.  
  18. }
  19.  
  20. int main()
  21. {
  22.     int n, m;
  23.     cin >> n >> m;
  24.     for (int i = 1; i <= n; i++)
  25.         for (int j = 1; j <= m; j++)
  26.             a[i][j] = -1;
  27.     Fill(1, 1);
  28.  
  29.     for (int i = 1; i <= n; i++){
  30.         for (int j = 1; j <= m; j++)
  31.             cout << a[i][j] << ' ';
  32.         cout << endl;
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement