I don't need to say much about the question.
Solution:
Since N is not large and the maximum character is 729*729 (3 ^ 6), you can use a two-dimensional array to store the characters that should be printed in each column of each line. Recursively assign the corresponding position to 'x '. The size of each recursion is the upper-layer size/3 until size = 1; each recursion transmits the corresponding coordinates.
Code:
# Include <cstdio> <br/> # include <cstring> <br/> # include <cmath> <br/> # define size 731 </P> <p> int getpow (int n) <br/>{< br/> return (INT) Pow (3, (double) N ); <br/>}</P> <p> char list [size] [size]; </P> <p> void FN (INT size, int X, int y) <br/>{< br/> If (size = 1) <br/>{< br/> list [x] [Y] = 'X '; <br/>}< br/> else <br/> {<br/> int d = size/3; <br/> FN (size/3, X, y); <br/> FN (size/3, X, Y + 2 * D); <br/> FN (size/3, X + D, Y + d); <br/> FN (size/3, x + 2 * D, Y); <br/> FN (size/3, X + 2 * D, Y + 2 * D); <br/>}</P> <p> int main () <br/>{< br/> int N; <br/> int size; <br/> while (scanf ("% d", & N) & n! =-1) <br/>{< br/> memset (list, 0, sizeof (list); <br/> size = getpow (n-1 ); <br/> FN (size, 0, 0); </P> <p> for (INT I = 0; I <size; ++ I) <br/>{< br/> for (Int J = 0; j <size; ++ J) <br/>{< br/> printf ("% C ", list [I] [J] = 'X '? 'X': ''); <br/>}< br/> printf ("/N "); <br/>}< br/> printf ("-/N"); <br/>}< br/> return 0; <br/>}