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;
}