ou_fan代码
Description |
每一次魔法矩阵施展魔法时,总是由矩阵中魔法力最强的魔法师率先发起,现有一个a行b列的矩阵,要求编程序找出其中魔法力最强的学员及所在的行号和列号 |
Input |
有多组数据,第一行一个正整数t(t<100)表示输入数据组数,接下来有t组输入数据,每组数据占a+1行,第一行包含两个整数a、b,1<=a<=b<=100,接下来跟随a行,每行包含用空格隔开的b个数字。 |
Output |
对于每组数据输出一行,包含两个整数,用空格隔开,行末不包含空格。 |
Sample Input |
1 1 1 5 |
Sample Output |
1 1 |
Hint |
数据保证,最大的只有一个 |
#include<iostream>
#include<math.h>
using namespace std;
int ans1, ans2;
int arr[105][105];
int main() {
int t;
cin >> t;
while(t--) {
ans1 = 1, ans2 = 1;
int a, b;
cin >> a >> b;
//扫描进入数组
for (int i = 1;i <= a;i++) {
for (int j = 1;j <= b;j++) {
cin >> arr[i][j];
}
}
//扫描最大数据
int max = arr[1][1];
for (int i = 1;i <= a;i++) {
for (int j = 1;j <= b;j++) {
if (arr[i][j] >max) {
ans1 = i, ans2 = j;
max = arr[i][j];
}
}
}
//输出数据
cout << ans1 <<' '<<ans2<< endl;
}
}
注意:使用max原先等于arr[1][1]