题目16:Repeater

http://ac.jobdu.com/problem.php?cid=1040&pid=15

题目描述:

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     
// 题目16:Repeater.cpp: 主项目文件。

#include "stdafx.h"
#include <cstdio>
#include <cstring>

const int M=6;
const int N=3001;
//const int NN=101;
char maze[M][M];
char map[N][N];
//char mapTemp[N][N];
int n;

void print(int m)
{
	for(int i=0;i<n;i++)
	{
		//strcpy(mapTemp[i],maze[i]);
		strcpy(map[i],maze[i]);
	}
	int s=n;
	for(int x=1;x<m;x++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				int startX=s*i,startY=s*j;
				if(!(i==0&&j==0)){
					if(maze[i][j]!=' '){
						for(int u=0;u<s;u++){
							for(int v=0;v<s;v++){
								map[startX+u][startY+v]=map[u][v];
								//if(i==0&&j==0)
								//mapTemp[u][v]=map[startX+u][startY+v];
							}
						}
					}
					else{
						for(int u=0;u<s;u++){
							for(int v=0;v<s;v++){
								map[startX+u][startY+v]=' ';
							}
						}
					}
				}
			}
		}
		if(maze[0][0]==' '){
			for(int i=0;i<s;i++)
				for(int j=0;j<s;j++)
					map[i][j]=' ';
		}
		s*=n;
	}
	for(int i=0;i<s;i++)
	{
		map[i][s]='\0';
		printf("%s\n",map[i]);
	}
}

int main()
{
	freopen("F:\\test.txt","r",stdin);
	freopen("F:\\output.txt","w",stdout);
	while(scanf("%d",&n)!=EOF&&n!=0)
	{
		getchar();
		for(int i=0;i<n;i++)
		{
			gets(maze[i]);
			//getchar();
		}
		int m;
		scanf("%d",&m);
		print(m);
		//printf(",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,\n");
	}
	return 0;
}


转载于:https://www.cnblogs.com/cjweffort/archive/2013/03/02/3374925.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值