pset4 cs50 反映错误
pset4 cs50 reflect eroor
此程序正确反映图像:
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
int wide=round(width/2);
for(int i=0;i<height;i++){
for (int j=0;j<=wide;j++){
RGBTRIPLE k=image[i][j];
image[i][j]=image[i][(width-j-1)];
image[i][width-j]=k;
}
}
return;
}
但是当我 运行 check50 时,它给出了以下错误:
:( reflect correctly filters 1x2 image
expected "0 0 255\n255 0...", not "0 0 255\n0 0 2..."
:( reflect correctly filters 1x3 image
expected "0 0 255\n0 255...", not "0 0 255\n0 255..."
:) reflect correctly filters image that is its own mirror image
:( reflect correctly filters 3x3 image
expected "70 80 90\n40 5...", not "70 80 90\n40 5..."
:( reflect correctly filters 4x4 image
expected "100 110 120\n7...", not "100 110 120\n7..."
:( blur correctly filters middle pixel
expected "127 140 149\n", not "120 140 150\n"
不知道是什么原因。
在此代码中:
RGBTRIPLE k=image[i][j];
image[i][j]=image[i][(width-j-1)];
image[i][width-j]=k;
image[i][width-j]
是错误的;它不是刚刚加载的要与 image[i][j]
交换的像素。应该是 image[i][width-1-j]
.
此程序正确反映图像:
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
int wide=round(width/2);
for(int i=0;i<height;i++){
for (int j=0;j<=wide;j++){
RGBTRIPLE k=image[i][j];
image[i][j]=image[i][(width-j-1)];
image[i][width-j]=k;
}
}
return;
}
但是当我 运行 check50 时,它给出了以下错误:
:( reflect correctly filters 1x2 image
expected "0 0 255\n255 0...", not "0 0 255\n0 0 2..."
:( reflect correctly filters 1x3 image
expected "0 0 255\n0 255...", not "0 0 255\n0 255..."
:) reflect correctly filters image that is its own mirror image
:( reflect correctly filters 3x3 image
expected "70 80 90\n40 5...", not "70 80 90\n40 5..."
:( reflect correctly filters 4x4 image
expected "100 110 120\n7...", not "100 110 120\n7..."
:( blur correctly filters middle pixel
expected "127 140 149\n", not "120 140 150\n"
不知道是什么原因。
在此代码中:
RGBTRIPLE k=image[i][j];
image[i][j]=image[i][(width-j-1)];
image[i][width-j]=k;
image[i][width-j]
是错误的;它不是刚刚加载的要与 image[i][j]
交换的像素。应该是 image[i][width-1-j]
.