输出不了数据,应该是找到问题了,但是不知道怎么改
查看原帖
输出不了数据,应该是找到问题了,但是不知道怎么改
974385
SeynChild楼主2023/7/6 11:30

没提交 应该是全WA?

C++代码如下:

#include <iostream>
using namespace std;

int main(void) {
	int a[5][5], max[5]={}, min[5]={};
	for (unsigned short h=0; h<5; h++) for (unsigned short w=0; w<5; w++) cin >> a[h][w];
	for (unsigned short h=0; h<5; h++) for (unsigned short w=0; w<5; w++) max[h]=a[h][w]>max[h]?a[h][w]:max[h];
	for (unsigned short w=0; w<5; w++) for (unsigned short h=0; h<5; h++) min[w]=a[h][w]>min[w]?min[w]:a[h][w];
	for (unsigned short h=0; h<5; h++) for (unsigned short w=0; w<5; w++) if (max[h]==min[w]) cout << h << " " << w << " " << max[h];
	return 0;
}

主要就是通过 max[5] 和 min[5] 来分别存储 每行的最大值 和 每列的最小值


但是输入题目中的数据是没有任何数据显示出来的:

无数据输出

然后我尝试输出数组 max[5] 和 min[5]:

其实就是把最后一个for循环:for (unsigned short h=0; h<5; h++) for (unsigned short w=0; w<5; w++) if (max[h]==min[w]) cout << h << " " << w << " " << max[h];改成for (int i=0; i<5; i++) cout << max[i] << " "; cout << endl; for (int i=0; i<5; i++) cout << min[i] << " "; cout << endl;

然后就输出了下面这个东西:

输出 max[5] 和 min[5]

也就是说 min[5] 数组的赋值是无效的

不知道为什么会出现这个情况,求大佬解答,感谢了!!

2023/07/06 11:30

2023/7/6 11:30
加载中...