1 #include <stdio.h> 2 3 4 5 6 struct MyPoint 7 { 8 int x; 9 int y; 10 }; 11 12 struct MyPoint p[(1<<13)+1]; 13 14 void fold(int n) 15 { 16 int i,c; 17 if (n==0) 18 { 19 p[0].x=0; 20 p[0].y=0; 21 p[1].x=1; 22 p[1].y=0; 23 return ; 24 } 25 fold(n-1); 26 c=1<<(n-1); 27 for (i=0;i<c;i++) 28 { 29 p[2*c-i].x=p[c].x+p[i].y-p[c].y; 30 p[2*c-i].y=p[c].y+p[c].x-p[i].x; 31 } 32 } 33 char map[400][400]; 34 35 int checkLine(struct MyPoint a,struct MyPoint b,int *x,int *y) 36 { 37 38 if (a.x==b.x) 39 { 40 *y=a.y>b.y?b.y:a.y; 41 *x=a.x; 42 return 2; 43 } 44 if (a.y==b.y) 45 { 46 *x=a.x>b.x?b.x:a.x; 47 *y=a.y; 48 return 1; 49 } 50 } 51 int findMinhx(int n) 52 { 53 int i; 54 int x=100; 55 int y=100; 56 int minhx=100; 57 int minvx=100; 58 for (i=0;i<1<<n;i++) 59 { 60 if (checkLine(p[i],p[i+1],&x,&y)==1) 61 { 62 if (minhx>x) 63 { 64 minhx=x; 65 } 66 } 67 if (checkLine(p[i],p[i+1],&x,&y)==2) 68 { 69 if (minvx>x) 70 { 71 minvx=x; 72 } 73 } 74 } 75 if (minhx<minvx) 76 { 77 return 1; 78 } 79 else 80 return 2; 81 } 82 void mapMap(int n,int tx) 83 { 84 int i,j; 85 int x,y; 86 int t; 87 for (i=0;i<400;i++) 88 { 89 for (j=0;j<(400);j++) 90 { 91 map[i][j]=' '; 92 } 93 } 94 for (i=0;i<1<<n;i++) 95 { 96 t=checkLine(p[i],p[i+1],&x,&y); 97 if (t==1) 98 { 99 if (tx==1) 100 { 101 map[x*2][y]='_'; 102 } 103 else 104 { 105 map[x*2+1][y]='_'; 106 } 107 } 108 else 109 { 110 if (tx==2) 111 { 112 map[x*2][y]='|'; 113 } 114 else 115 { 116 map[x*2-1][y]='|'; 117 } 118 } 119 } 120 } 121 void outputmap(int x,int y) 122 { 123 int i,j; 124 int t; 125 for(j=399;j>=0;j--) 126 { 127 for (i=399;i>=0;i--) 128 { 129 if (map[i][j]!=' '&&map[i][j]!=0) 130 { 131 break; 132 } 133 } 134 t=i; 135 if (t<0) 136 { 137 continue; 138 } 139 140 for (i=0;i<=t;i++) 141 { 142 printf("%c",map[i][j]); 143 } 144 printf("\n"); 145 } 146 printf("^\n"); 147 148 149 } 150 int main(){ 151 int n; 152 int i,minx,miny,maxx,maxy,j; 153 int t; 154 while (scanf("%d",&n),n) 155 { 156 for (i=0;i<(400);i++) 157 { 158 for (j=0;j<(400);j++) 159 { 160 map[i][j]=' '; 161 } 162 } 163 fold(n); 164 minx=100; 165 miny=100; 166 maxx=0; 167 maxy=0; 168 for (i=0;i<(1<<n)+1;i++) 169 { 170 if (p[i].x<minx) 171 { 172 minx=p[i].x; 173 } 174 if (p[i].y<miny) 175 { 176 miny=p[i].y; 177 } 178 if (p[i].x>maxx) 179 { 180 maxx=p[i].x; 181 } 182 if (p[i].y>maxy) 183 { 184 maxy=p[i].y; 185 } 186 } 187 for (i=0;i<(1<<n)+1;i++) 188 { 189 p[i].x-=minx; 190 p[i].y-=miny; 191 } 192 t=findMinhx(n); 193 maxx-=minx; 194 maxy-=miny; 195 mapMap(n,t); 196 outputmap(maxx,maxy); 197 198 199 } 200 return 0; 201 }