Problem Solving/Baekjoon Online Judge
BOJ/백준 2566번 최댓값
khj1999
2019. 5. 16. 03:33
https://www.acmicpc.net/problem/2566
2566번: 최댓값
첫째 줄에 최댓값을 출력하고, 둘째 줄에 최댓값이 위치한 행 번호와 열 번호를 빈칸을 사이에 두고 차례로 출력한다. 최댓값이 두 개 이상인 경우 그 중 한 곳의 위치를 출력한다.
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arr[][] = new int[9][9];
int check_1 = 0,check_2 = 0, max = 0;
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < arr[i].length; j++) {
arr[i][j] = sc.nextInt();
}
}
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j < arr[i].length; j++) {
if(arr[i][j] > max) {
max = arr[i][j];
check_1 = i+1;
check_2 = j+1;
}
}
}
System.out.println(max);
System.out.println(check_1 +" "+ check_2);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
배열을 검사하면서 최댓값이 바뀔때마다 i,j의 값도 같이 바꿔주면 된다.
아직 잘모르는 초보이니 오류지적 해주시면 감사하겟습니다.