hdu oj 2022 不用二维数组,两个for循环实现

版权声明:本博客为博主原创文章,未经博主允许,禁止转载,谢谢合作。 https://blog.csdn.net/weixin_43971252/article/details/88309686

题目:hdu oj 2002
思路:定义一个存储最大绝对值的变量,用两个循环模拟行和列,在输入分数时找出最大值,行,列。
vs2019运行:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>

int main()
{
	int m, n;

	while (scanf("%d %d", &m, &n) != EOF) {
		int score, abs_of_max;
		int line, row;
		for(int i=0;i<m;i++)
			for (int j = 0; j < n; j++) {
				scanf("%d", &score);
					if ( (i == 0 && j == 0) || abs(score) > abs(abs_of_max))
					{
						abs_of_max = score;
						line = i + 1, row = j + 1;
					}
			}
		printf("%d %d %d\n", line, row, abs_of_max);
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43971252/article/details/88309686