KY58 Repeater

题目描述

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 NN (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 30003000.

输出描述:
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<stdlib.h>

char template_1[3001][3001];
char template_new[3001][3001];

void repeat(int i_start, int j_start, int size) {
    for (int i = i_start; i < size + i_start; i ++) {
        for (int j = j_start; j < size + j_start; j ++) {
            template_new[i][j] = template_1[i - i_start][j - j_start];
        }
    }
}

void copy(int size) {
    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j ++) {
            template_1[i][j] = template_new[i][j];
        }
    }
}

void print(int size) {
    for (int i = 0; i < size; i++) {
        for (int j = 0; j < size; j ++) {
            printf("%c", template_1[i][j]);
        }
        printf("\n");
    }
}

int main() {
    int size;
    int num_temp[6][6];
    int num_size;
    scanf("%d", &size);
    num_size = size;
    // 记录原图的数字矩阵, 依次记录最高等级的模板,按着数字矩阵输出
    for (int i = 0; i < size; i ++) {
        for (int j = 0; j < size; j ++) {
            template_1[i][j] = getchar();
            while(template_1[i][j] == '\n'){
				template_1[i][j] = getchar();
			}
//            char jc = template_1[i][j];
            if (template_1[i][j] != ' ') {
                num_temp[i][j] = 1;
            }
            else {
                num_temp[i][j] = 0;
            }
        }
    }
    int level;
    scanf("%d", &level);
    while (level != 1) {
        // 检查数字矩阵对应的数字,为1时, 将template中的矩阵放置在template_new中
        // 最后将template_new中的矩阵复制在template中。
        for (int i = 0; i < num_size; i ++) {
            for (int j = 0; j < num_size; j ++) {
                if (num_temp[i][j] == 1) {
                    // 这里的尺寸与ijsize有关。
                    repeat(i * size, j * size, size);
                }
            }
        }
        size *= num_size;
        copy(size);
        level --; 
    }
    print(size);
    return 0;
}

本地ide与在线调试都给出正确结果,暂时先这样。
找到解决办法时候更新答案注释。

记录一下scanf(“%c”)与 getchar()的关系,关系相同,均默认读入换行与空格,但scanf(“%s”)不读入非空白字符前的所有字符,遇见空白字符停止读入,改空白字符留在缓冲区中,gets()遇见换行符停止读入,并读入换行符,如果第一个字符是换行, scanf(“%s”)会跳过,gets()会仅仅读入该换行符。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值