-
재귀를 이용해주면 됩니다. 3으로 나눈 나머지 어쩌구 저쩌구 잔꾀같은거 안부립니다.
#include <bits/stdc++.h> using namespace std; #define N 6561 int arr[6600][6600] = {}; void f(int x, int y, int n) { if (n == 3) { arr[x][y] = 1; arr[x+1][y] = 1; arr[x+2][y] = 1; arr[x][y+1] = 1; arr[x][y+2] = 1; arr[x+1][y+2] = 1; arr[x+2][y+1] = 1; arr[x+2][y+2] = 1; return; } int t = n / 3; f(x, y, t); f(x, y + t, t); f(x, y+2*t, t); f(x+t, y, t); f(x+2*t, y, t); f(x+t, y+2*t, t); f(x+2*t, y+t, t); f(x+2*t, y+2*t, t); } int main(void) { int n; cin >> n; f(0, 0, n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (arr[i][j]) cout << "*"; else cout << " "; } cout << "\n"; } }