#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <cstring>
#include <sstream>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#include <cstdlib>
using namespace std;
char Answer[730][730];
char getAnswer(int n,int ci,int cj);
void fill_(int n,int ci,int cj){
if(n == 1){
Answer[ci][cj] = 'X';
return ;
}
getAnswer(n,ci,cj);
}
char getAnswer(int n,int ci,int cj){
int len = pow(3,n - 2);
fill_(n - 1,ci,cj); //左
fill_(n - 1,ci,cj + len * 2);//右
fill_(n - 1,ci + len, cj + len);//中
fill_(n - 1,ci + len * 2, cj);//左下
fill_(n - 1,ci + len * 2,cj + len * 2);//右下
}
int main(){
int n;
while(cin >> n && n != -1){
memset(Answer,' ',sizeof(Answer));
if(n == 1){
cout << "X\n";
cout << "-\n";
continue;
}
getAnswer(n,0,0);
int len = pow(3,n - 1);
for(int i = 0; i < len; i++){
for(int j = 0; j < len; j++){
cout << Answer[i][j];
}
cout << endl;
}
cout << "-\n";
}
return 0;
}
来源:CSDN
作者:weixin_44368514
链接:https://blog.csdn.net/weixin_44368514/article/details/104795234