在单色位图像中,构成图像的每个像素都具有0或1的颜色信息,创建图像时,已经确定了图像的大小和构成图像的所有像素的信息。
现在我们想将图像放大,而放大图像的最简单的方法是在保持现有像素排列的情况下,平均增加每个像素的数量,
输入描述:
第一行给出正方形单色位图的水平/垂直长度 N和用于放大图像的倍数K
第二行到第N+ 1行中,每行给出N个像素的信息。1≤N,K≤10
例:
输入:
2 2
0 1
1 0
输出:
0 0 1 1
0 0 1 1
1 1 0 0
1 1 0 0
C语言:
#include <stdio.h>
int main()
{
int n = 0, k = 0;
scanf("%d %d", &n, &k);
char a[n][n];
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
scanf("%d", &a[i][j]);
char b[n*k][n*k];
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
for(int c = 0; c < k; ++c){
for(int d = 0; d < k; ++d){
b[i * k + c][j * k + d] = a[i][j];
}
}
}
}
for(int i = 0; i < n * k; ++i){
for(int j = 0; j < n * k; ++j){
printf("%d ", b[i][j]);
}
printf("\n");
}
return 0;
}
说明:因为只有每个像素都只有01的差别,所有感觉有点浪费空间,所以使用char,而不是int型。