http://acm.hdu.edu.cn/showproblem.php?pid=2022
还没入门,只能从最基本的问题开始打基础!
思路一:按二维数组的思维处理
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
int m,n;
int a, b;
int i, j;
int x, y;
while (cin >> m >> n)
{
b = 0;
for (i = 0; i<m; i++)
{
for (j = 0; j<n; j++)
{
cin >> a;
if (abs(a)>abs(b))
{
b = a;
x = i;
y = j;
}
}
}
cout << x+1 << " " << y+1 << " " << b << endl;
}
return 0;
}<span style="font-family:Microsoft YaHei;font-size:18px;">
</span>
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
int m,n;
int a, b,c;
while (cin >> m >> n)
{
b = 0;
for (int i = 0; i<m*n; i++)
{
cin >> a;
if (abs(a)>abs(b))
{
b = a;
c = i;
}
}
cout << c/n+1 << " " << c%n+1 << " " << b << endl;
}
return 0;
}<span style="font-family:Microsoft YaHei;font-size:18px;">
</span>
行:x=k/n+1;
列:y=k%n+1;