Advertisement
mickypinata

SMMR-T043: Pattern

Jun 3rd, 2021
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 500;
  5.  
  6. bool board[N + 10][N + 10];
  7.  
  8. void fillBoard(int idx, int x){
  9.     if(x <= 0){
  10.         return;
  11.     }
  12.     for(int i = idx; i < idx + x; ++i){
  13.         board[i][idx] = true;
  14.         board[idx][i] = true;
  15.         board[idx + x - 1][i] = true;
  16.         board[i][idx + x - 1] = true;
  17.     }
  18.     fillBoard(idx + 2, x - 4);
  19. }
  20.  
  21. int main(){
  22.  
  23.     int sz;
  24.     scanf("%d", &sz);
  25.     fillBoard(1, sz);
  26.  
  27.     for(int i = 1; i <= sz; ++i){
  28.         for(int j = 1; j <= sz; ++j){
  29.             if(board[i][j]){
  30.                 cout << '*';
  31.             } else {
  32.                 cout << '-';
  33.             }
  34.         }
  35.         cout << '\n';
  36.     }
  37.  
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement