题目描述
和谐在我们的日常生活中是不可或有的,没有它----,也许面是唯一的例外。有一天,有传言说,重复绘画将创造和谐,然后数百人开始他们无尽的绘画。他们的绘画是基于一个小模板和一个简单的复制方法。虽然 Facer 很容易想象整个画面的风格,但他找不到本质的和谐。现在,您需要通过在计算机上显示图片来帮助 Facer。将为他们提供一个模板,仅包含一种字符和空格,模板显示如何创建无尽的图片----将字符用作基本元素,并将它们放在正确的位置以形成更大的模板,然后重复并重复这样做。下面是一个示例。* *#
输入描述:
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.
输出描述:
For each test case, just print the Level Q picture by using the given template.
input:
3
# #
#
# #
1
3
# #
#
# #
3
4
OO
O O
O O
OO
2
0
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
one answer from a coder:
#include <stdio.h>
#include <math.h>
char d[3000][3000];
char s[6][6];
int n,m;
//递归画图
void dfs(int m,int x,int y) // m是扩张的维度,x是,y是基准坐标,第一个开始被分解的坐标
{
int i,j;
if(m==1)
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
d[x+i][y+j]=s[i][j];
}
}
return;
}
int size=pow(n,m-1); // 下一层的大小
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(s[i][j]!=' ')
dfs(m-1,x+i*size,y+j*size); //对于不是空格的部分才进行扩展,是空格的部分不进行扩展
}
}
}
int main()
{
int size;
while(scanf("%d",&n)!=EOF)
{
getchar();
if(n==0)
break;
int i,j;
for(i=0;i<n;i++)
{
gets(s[i]);
}
scanf("%d",&m); // m是扩展的大小
size=pow(n,m); // 整体的大小,行数和列数
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
d[i][j]=' ';
}
d[i][size]='\0'; //注意,需要在末尾加结束符'\0',因为这样才能够正常输出字符数组
}
dfs(m,0,0);
for(i=0;i<size;i++)
printf("%s\n",d[i]);
}
return 0;
}