王道机试:模拟类

1.Repeater

输入描述:
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 <iostream>
#include <cstdio>
#include <cmath>
#include <string.h>
using namespace std;

char map[3003][3003];
char str[6][6];
int n;

void dfs(int m, int x, int y){
    if (m == 1){
        for (int i = 0; i<n; i++)
            for (int j = 0; j<n; j++)
                map[x + i][y + j] = str[i][j];
        return;
    }
    int size = (int)pow(n*1.0, m - 1);
    for (int i = 0; i<n; i++){
        for (int j = 0; j<n; j++){
            if (str[i][j] != ' ')
                dfs(m - 1, x + i*size, y + j*size);
        }
    }
}

int main(void){
    n = 1;
    while (n){
        cin >> n;
        getchar();
        for (int i = 0; i < n; i++){
            cin.getline(str[i],6);
        }
        int m;
        cin >> m;
        int size = (int)pow(n*1.0, m);
        for (int i = 0; i<size; i++){
            for (int j = 0; j<size; j++)
                map[i][j] = ' ';
            map[i][size] = '\0';
        }
        dfs(m, 0, 0);
        for (int i = 0; i<size; i++)
            cout<<map[i]<<endl;
    }
    return 0;
} 
	


2.KY147 Hello World for U

牛客网

#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    while(cin>>s){
        int len=s.size();
        len+=2;
        int l=len/3-1;//(len+2)/3就是n1和n2的值
        int mid=len-len/3*2;
        for(int i=0;i<l;i++){
            cout<<s[i];
            for(int j=0;j<mid-2;j++)   cout<<" ";
            cout<<s[s.size()-1-i]<<endl;
        }
        for(int i=l;i<l+mid;i++){
            cout<<s[i];
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值