-
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 is ended with a case of N=0把N看成了Q所以一直超时。。。
另外这道题目还需要考虑空格的输入,不能直接CIN会把空格漏掉的,具体可以参考下博客中的C++输入问题
另外这道题也可以使用地柜来计算
题目描述:
-
输入:
-
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
#include <stdio.h> #include <iostream> #include <string> #include <string.h> #include <algorithm> #include <cmath> using namespace std; char c[3000][3000]; char cMark[3000][3000]; char cOrg[5][5]; void init(int a,int b,int n) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { c[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++) { c[a*n+i][b*n+j] = cMark[i][j]; } } } void upDate(int iCoun) { for (int j=0;j<iCoun;j++) { for (int k=0;k<iCoun;k++) { cMark[j][k]=c[j][k]; } } } int main() { int N=3,Q=1,i,j; while(N!=0) { cin>>N; getchar(); for (i=0;i<N;i++) { cin.getline(c[i],N+1); memcpy(cOrg[i],c[i],6); } cin>>Q; if (0==Q) { return 0; } int iCoun=N; int k=0,l=0,m=0; for (i=2;i<=Q;i++) { upDate(iCoun); for (j=0;j<N;j++) { for (k=0;k<N;k++) { if (cOrg[j][k]==' ') { init(j,k,iCoun); } else { copy(j,k,iCoun); } } } iCoun=pow(N,i);//iCoun*N; } for (i=0;i<iCoun;i++) { for (j=0;j<iCoun;j++) { cout<<c[i][j]; } cout<<endl; } } return 0; }