-
题目描述:
-
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# # # #
# #
# # # #
# #
#
# #
# # # #
# #
# # # #
-
输入:
-
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.
-
样例输入:
-
3 # # # # # 1 3 # # # # # 3 4 OO O O O O OO 2 0
-
样例输出:
-
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 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
在自己的机器上一直得到错误的图形,但却能AC过,参考网上的资料而成的代码,所参考的代码也是在自己的机器上无法正确显示,但是AC。疑惑。。。
#include<stdio.h>
#include<string.h>
#include<math.h>
char buf[3000][3000];
char sample[3000][3000];
char start[6][6];
void init(int a, int b, int n) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
buf[a * n + i][b * n + j] = ' ';
}
void copy(int a, int b, int n) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
buf[a * n + i][b * n + j] = sample[i][j];
}
void update(int n) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
sample[i][j] = buf[i][j];
}
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n == 0)
break;
getchar();//吸收掉上一行的回车换行符
for (int i = 0; i < n; i++) {
gets(buf[i]);
strcpy(start[i], buf[i]);
}
int scale;
scanf("%d", &scale);
int size = n;
for (int k = 2; k <= scale; k++) {
update(size);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (start[i][j] == ' ')
init(i, j, size);
else
copy(i, j, size);
}
}
size = pow(n, k);
}
// printf("the sample is:\n");
// for (int i = 0; i < size / n; i++) {
// for (int j = 0; j < size / n; j++)
// printf("%c", sample[i][j]);
// printf("\n");
// }
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++)
printf("%c", buf[i][j]);
printf("\n");
}
}
return 0;
}
参考链接:
http://blog.csdn.net/huiyuanai222/article/details/39967603
题目链接:
http://ac.jobdu.com/problem.php?pid=1161