让一个图放大缩小,根本不用多开数组,直接使用原字符数组进行循环控制,两种方法
方法一:循环控制行列
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e3+50;
char h[5][100] = {"*****..***..*...*.*****...*...*.*****.*****.***...*****.*...*",
"*.....*...*.*...*.*.......*...*.*...*...*...*..*..*...*..*.*.",
"*****.*****.*...*.***.....*****.*****...*...*...*.*...*...*..",
"....*.*...*..*.*..*.......*...*.*.*.....*...*..*..*...*...*..",
"*****.*...*...*...*****...*...*.*..**.*****.***...*****...*.."
};
char v[61][10] = { "*****",
"*....",
"*****",
"....*",
"*****",
".....",
".***.",
"*...*",
"*****",
"*...*",
"*...*",
".....",
"*...*",
"*...*",
"*...*",
".*.*.",
"..*..",
".....",
"*****",
"*....",
"***..",
"*....",
"*****",
".....",
".....",
".....",
"*...*",
"*...*",
"*****",
"*...*",
"*...*",
".....",
"*****",
"*...*",
"*****",
"*.*..",
"*..**",
".....",
"*****",
"..*..",
"..*..",
"..*..",
"*****",
".....",
"***..",
"*..*.",
"*...*",
"*..*.",
"***..",
".....",
"*****",
"*...*",
"*...*",
"*...*",
"*****",
".....",
"*...*",
".*.*.",
"..*..",
"..*..",
"..*.."
};
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n){
if(n>0){
for(int i=0;i<5;i++){
int temp=0;//n行
while(temp<n){
for(int j=0;h[i][j];j++){
int cnt=0;//n个
while(cnt<n){
printf("%c",h[i][j]);
++cnt;
}
}
temp++;
printf("\n");
}
}
}else{
n=-n;
for(int i=0;i<61;i++){
int temp=0;
while(temp<n){
for(int j=0;v[i][j];j++){
int cnt=0;
while(cnt<n){
printf("%c",v[i][j]);
cnt++;
}
}
temp++;
printf("\n");
}
}
}
printf("\n\n");
}
return 0;
}
第二种:输入n,然后放大n倍,也就是在字符数组上f[(i-1)/n+1][(j-1)/n+1]
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e3+50;
char h[6][101] = {" ",
" *****..***..*...*.*****...*...*.*****.*****.***...*****.*...*",
" *.....*...*.*...*.*.......*...*.*...*...*...*..*..*...*..*.*.",
" *****.*****.*...*.***.....*****.*****...*...*...*.*...*...*..",
" ....*.*...*..*.*..*.......*...*.*.*.....*...*..*..*...*...*..",
" *****.*...*...*...*****...*...*.*..**.*****.***...*****...*.."};
char v[62][11] = { " ",
" *****",
" *....",
" *****",
" ....*",
" *****",
" .....",
" .***.",
" *...*",
" *****",
" *...*",
" *...*",
" .....",
" *...*",
" *...*",
" *...*",
" .*.*.",
" ..*..",
" .....",
" *****",
" *....",
" ***..",
" *....",
" *****",
" .....",
" .....",
" .....",
" *...*",
" *...*",
" *****",
" *...*",
" *...*",
" .....",
" *****",
" *...*",
" *****",
" *.*..",
" *..**",
" .....",
" *****",
" ..*..",
" ..*..",
" ..*..",
" *****",
" .....",
" ***..",
" *..*.",
" *...*",
" *..*.",
" ***..",
" .....",
" *****",
" *...*",
" *...*",
" *...*",
" *****",
" .....",
" *...*",
" .*.*.",
" ..*..",
" ..*..",
" ..*.."
};
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n){
if(n>0){
for(int i=1;i<=5*n;i++){
for(int j=1;j<=61*n;j++){
printf("%c",h[(i-1)/n+1][(j-1)/n+1]);
}
printf("\n");
}
}else{
n=-n;
for(int i=1;i<=61*n;i++){
for(int j=1;j<=5*n;j++){
printf("%c",v[(i-1)/n+1][(j-1)/n+1]);
}
printf("\n");
}
}
printf("\n\n");
}
return 0;
}