cs50 pset4/less 反映 check50 不工作
cs50 pset4/less reflect check50 not working
我的代码可以正常编译和运行,但是当我使用 check50 时,它说满足 'requirements' 的 none。
:( reflect correctly filters 1x2 image
expected "0 0 255\n255 0...", not "3 0 0\n0 0 255..."
:( reflect correctly filters 1x3 image
expected "0 0 255\n0 255...", not "246 55 65\n0 2..."
:( reflect correctly filters image that is its own mirror image
expected "255 0 0\n255 0...", not "0 255 0\n255 0..."
:( reflect correctly filters 3x3 image
expected "70 80 90\n40 5...", not "110 130 140\n4..."
:( reflect correctly filters 4x4 image
expected "100 110 120\n7...", not "110 130 140\n1..."
代码:
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
void swap (RGBTRIPLE*, RGBTRIPLE*);
for (int i = 0; i < height; i++)
{
int n = 1;
for (int j = 0; j < width / 2; j++)
{
swap (&image[i][j], &image[i][(width - j)]);
n++;
}
}
return;
}
void swap (RGBTRIPLE*a, RGBTRIPLE*b)
{
RGBTRIPLE tempArray;
RGBTRIPLE tempArray2;
tempArray = *a;
tempArray2 = *b;
*a = tempArray2;
*b = tempArray;
}
我浏览了很多其他帖子,但找不到任何解决方案。这可能只是一些小细节,但我找不到。
任何帮助是极大的赞赏。谢谢!
假设j == 0
你执行
swap (&image[i][j], &image[i][(width - j)]);
交换元素的索引是什么?它们合法吗?
它可能与您的交换函数调用一样简单。 swap 的第二个参数如果是
可能会更好
swap (&image[i][j], &image[i][width-1-j])
这对眼睛来说不会有太大的不同,但它可能会对 Cs50 检查程序产生很大的影响。
我的代码可以正常编译和运行,但是当我使用 check50 时,它说满足 'requirements' 的 none。
:( reflect correctly filters 1x2 image
expected "0 0 255\n255 0...", not "3 0 0\n0 0 255..."
:( reflect correctly filters 1x3 image
expected "0 0 255\n0 255...", not "246 55 65\n0 2..."
:( reflect correctly filters image that is its own mirror image
expected "255 0 0\n255 0...", not "0 255 0\n255 0..."
:( reflect correctly filters 3x3 image
expected "70 80 90\n40 5...", not "110 130 140\n4..."
:( reflect correctly filters 4x4 image
expected "100 110 120\n7...", not "110 130 140\n1..."
代码:
void reflect(int height, int width, RGBTRIPLE image[height][width])
{
void swap (RGBTRIPLE*, RGBTRIPLE*);
for (int i = 0; i < height; i++)
{
int n = 1;
for (int j = 0; j < width / 2; j++)
{
swap (&image[i][j], &image[i][(width - j)]);
n++;
}
}
return;
}
void swap (RGBTRIPLE*a, RGBTRIPLE*b)
{
RGBTRIPLE tempArray;
RGBTRIPLE tempArray2;
tempArray = *a;
tempArray2 = *b;
*a = tempArray2;
*b = tempArray;
}
我浏览了很多其他帖子,但找不到任何解决方案。这可能只是一些小细节,但我找不到。 任何帮助是极大的赞赏。谢谢!
假设j == 0
你执行
swap (&image[i][j], &image[i][(width - j)]);
交换元素的索引是什么?它们合法吗?
它可能与您的交换函数调用一样简单。 swap 的第二个参数如果是
可能会更好swap (&image[i][j], &image[i][width-1-j])
这对眼睛来说不会有太大的不同,但它可能会对 Cs50 检查程序产生很大的影响。