본문 바로가기

프로그래밍언어/알고리즘

백준 2566 최댓값_JAVA

https://www.acmicpc.net/problem/2566

 

2566번: 최댓값

첫째 줄에 최댓값을 출력하고, 둘째 줄에 최댓값이 위치한 행 번호와 열 번호를 빈칸을 사이에 두고 차례로 출력한다. 최댓값이 두 개 이상인 경우 그 중 한 곳의 위치를 출력한다.

www.acmicpc.net

 

 

 

 

 

import java.util.Scanner;

public class Main {

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int [][] arr = new int[9][9];
        int max = 0 ;
        int x = 0 ,y = 0;

        for (int i = 0 ; i <9 ; i++){

            for(int j = 0 ; j < 9; j++){
                arr[i][j] = sc.nextInt();

                if (arr[i][j] > max){
                    max = arr[i][j];
                    x = i;
                    y = j;
                }
            }

        }

        System.out.println(max);
        System.out.println( (x+1)+ " " + (y+1));

    }

}