-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
해결됨
봉우리 문제 정답인 것 같은데 뭐가 문제인지 잘 모르겠습니다..
23.05.02 17:57 작성 조회수 311
1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Main t = new Main();
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int[][] arr = new int[n][n];
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
arr[i][j] = kb.nextInt();
}
}
System.out.println(t.solution(n, arr));
}
public int solution(int n, int[][] arr) {
int answer = 0;
boolean isTop;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
isTop = true;
int center = arr[i][j];
if (i != 0) //상
if (arr[i - 1][j] > center)
isTop = false;
if (i != n - 1) //하
if (arr[i + 1][j] > center)
isTop = false;
if (j != 0) //좌
if (arr[i][j - 1] > center)
isTop = false;
if (j != n - 1) //우
if (arr[i][j + 1] > center)
isTop = false;
if (isTop)
answer++;
}
}
return answer;
}
}
정답은 잘 나오는 것 같은데.. 채점받으면 오답이라 나옵니다.. 무엇이 문제일까요? ㅠ
답변을 작성해보세요.
답변 1