海选女主角

来源:互联网 发布:淘宝商家信誉怎么看 编辑:程序博客网 时间:2024/04/17 06:13

Input
输入数据有多组,每组的第一行是两个整数m和n,表示应聘MM的总共的行列数,然后是m行整数,每行有n个,m和n的定义见题目的描述。 
Output
对于每组输入数据,输出三个整数x,y和s,分别表示选中的MM的行号、列号和分数。 
note:行号和列号从一开始,如果有多个MM的分数绝对值一样,那么输出排在最前面的一个(即行号最小的那个,如果行号相同则取列号最小的那个)。 
Sample Input
2 3
1 4 -3
-7 3 0
Sample Output

2 1 -7

package MainTest;import java.util.Scanner;  //求解矩阵里面的绝对值最大的数,采用打擂台的方法求解最大值,一个小技巧:只需求出行号和列号即可,public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        while (sc.hasNext()) {            int n = sc.nextInt();            int m = sc.nextInt();            int x = 1;            int y = 1;            int[][] arr = new int[n + 1][m + 1];            for (int i = 1; i <= n; i++) {                for (int j = 1; j <= m; j++) {                    arr[i][j] = sc.nextInt();                    if (Math.abs(arr[x][y]) < Math.abs(arr[i][j])) {                        x = i;                        y = j;                    }                }            }            int temp = arr[x][y];            System.out.println(x + " " + y + " " + temp);        }    }  }