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
参考别人代码写的,自己一开始没找到规律。
package com.zhanghaipeng.jobdu;
import java.util.Scanner;
public class JD1161 {
private static char[][] oriBuffer;
private static char[][] finBuffer;
private static int n;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
n = Integer.parseInt(sc.nextLine());
if (n == 0) {
break;
}
oriBuffer = new char[n][n];
for (int i = 0; i < n; i++) {
oriBuffer[i] = sc.nextLine().toCharArray();
}
int r = Integer.parseInt(sc.nextLine());
int size = n;
for (int i = 1; i < r; i++) {
size *= n;
}
finBuffer = new char[size][size];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
finBuffer[i][j] = ' ';
}
}
// 核心代码
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (oriBuffer[i][j] != ' ') {
draw(r, i, j);
}
}
}
for (int i = 0; i < size; i++) {
System.out.println(new String(finBuffer[i]));
}
}
}
private static void draw(int r, int x, int y) {// 每次画出图形的一个元素。
if (r == 1) {
finBuffer[x][y] = oriBuffer[x % n][y % n];// 画出一个对应的字符,不是整个图形。循环输出每个图形。
return;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (oriBuffer[i][j] != ' ') {
draw(r - 1, x * n + i, y * n + j);
}
}
}
}
}