天天看点

重复画图

Repeater
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 70(21 users) Total Accepted: 33(18 users) Rating: 
重复画图
重复画图
重复画图
重复画图
Special Judge: No
Description

Harmony is indispensible in our daily life and no one can live without it----may be Facer is the only exception. One day it is rumored that repeat painting will create harmony and then hundreds of people started their endless drawing. Their paintings were based on a small template and a simple method of duplicating. Though Facer can easily imagine the style of the whole picture, but he cannot find the essential harmony. Now you need to help Facer by showing the picture on computer.

You will be given a template containing only one kind of character and spaces, and the template shows how the endless picture is created----use the characters as basic elements and put them in the right position to form a bigger template, and then repeat and repeat doing that. Here is an example.

# #
 #      <-template
# #      
So the Level 1 picture will be
# #
 #
# #      
Level 2 picture will be

# #   # #  #     # # #   # #    # #        #        # #    # #   # #  #     #  # #   # #

Input

The input contains multiple test cases.

The first line of each case is an integer N, representing the size of the template is N*N (N could only be 3, 4 or 5).

Next N lines describe the template.

The following line contains an integer Q, which is the Scale Level of the picture.

Input is ended with a case of N=0.

It is guaranteed that the size of one picture will not exceed 3000*3000.

Output
For each test case, just print the Level Q picture by using the given template.
Sample Input

3

# #

 # 

# #

1

3

# #

 # 

# #

3

4

 OO 

O  O

O  O

 OO 

2

Sample Output

# #

 #

# #

# #   # #         # #   # #

 #     #           #     #

# #   # #         # #   # #

   # #               # #

    #                 #

   # #               # #

# #   # #         # #   # #

 #     #           #     #

# #   # #         # #   # #

         # #   # #

          #     #

         # #   # #

            # #

             #

            # #

         # #   # #

          #     #

         # #   # #

# #   # #         # #   # #

 #     #           #     #

# #   # #         # #   # #

   # #               # #

    #                 #

   # #               # #

# #   # #         # #   # #

 #     #           #     #

# #   # #         # #   # #

     OO  OO

    O  OO  O

    O  OO  O

     OO  OO

 OO          OO

O  O        O  O

O  O        O  O

 OO          OO

 OO          OO

O  O        O  O

O  O        O  O

 OO          OO

     OO  OO

    O  OO  O

    O  OO  O

     OO  OO

代码参考

#include <stdio.h>
#include <string.h>
#include <math.h>
char a[3002][3002];
char asdf;
char b[6];
int num,n;
int flag[6][6];
void dayin(int cur,int x,int y)
{
    if(cur==1)
    {
        a[x][y]=asdf;
        return ;
    }
    int s=pow(n,cur-2);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(flag[i][j]==1)
                dayin(cur-1,x+i*s,y+j*s);
        }
    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        if(n==0) break;
        getchar();
        memset(a,' ',sizeof(a));
        memset(flag,0,sizeof(flag));


        for(int i=0; i<n; i++)
        {
            gets(b);
            for(int j=0; j<n; j++)
            {
                if(b[j]!=' ')
                {
                    asdf=b[j];
                    flag[i][j]=1;
                }
            }
        }


        int m;
        scanf("%d",&m);
        int s=pow(n,m);
        dayin(m+1,1,1);


        for(int i=1; i<=s; i++)
        {
            a[i][s+1]='\0';


            puts(a[i]+1);
        }
    }
    return 0;
}