#include <iostream> #include <cmath> using namespace std; #define SIZE 2001 #define base 3 #define multiple 2 char p[SIZE][SIZE]; void universe(int n, int x, int y) { if (n == 1) p[x][y] = 'X'; else { int size = pow(base, n - multiple); universe(n - 1, x, y); universe(n - 1, x, y + size * multiple); universe(n - 1, x + size, y + size); universe(n - 1, x + size * multiple, y); universe(n - 1, x + size * multiple, y + size * multiple); } } int main() { int n = 0; while (cin >> n) { int size = pow(base, n - 1); for (int i = 1; i <= size; ++i) { for (int j = 1; j <= size; ++j) p[i][j] = ' '; } universe(n, 1, 1); for (int i = 1; i <= size; ++i) { for (int j = 1; j <= size; ++j) cout << p[i][j]; cout << endl; } cout << "-" << endl; } }
标签:multiple,int,universe,宇宙,分形,base,SIZE,size From: https://www.cnblogs.com/lhf123/p/17279024.html