一行一行的输出比一个字符一个字符的输出快了10倍
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
using namespace std;
template<typename T>
T fpow(T a, T b) {
T ans = 1;
while (b) {
if (b & 1)ans *= a;
b >>= 1;
a *= a;
}
return ans;
}
char ans[750][750];
int n,len;
void dfs(int now, int x, int y) {
if (now == 1) {
ans[x][y] = 'X';
return;
}
int s = fpow(3, now - 2);
dfs(now - 1, x, y);
dfs(now - 1, x, y + s * 2);
dfs(now - 1, x + s, y + s);
dfs(now - 1, x + s * 2, y);
dfs(now - 1, x + s * 2, y + s * 2);
}
int main() {
while (scanf("%d", &n), n != -1) {
memset(ans, ' ', sizeof(ans));
len = fpow(3, n - 1);
dfs(n, 0, 0);
for (int i = 0; i < len; i++)
ans[i][len + 1] = '\0';
for (int i = 0; i < len; i++)
printf("%s\n", ans[i]);
printf("-\n");
}
return 0;
}