개발자 톡

연습문제 톡 진정한 효도

반례 알려주세요!!

등록일
2024-06-28 14:29:57
조회수
49
작성자
ne2227
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int[][] arr = new int[3][3];

        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                arr[i][j] = sc.nextInt();
            }
        }
        int answer = Integer.MAX_VALUE;

        // 가로 검사
        for(int i = 0; i < 3; i++) {
            int tmp = 0;
            int min = Arrays.stream(arr[i]).min().getAsInt();
            for (int j = 0; j < 3; j++) {
                tmp += arr[i][j] - min;
            }
            answer = Math.min(answer, tmp);
        }
        if (answer == 0) {
            System.out.println(answer);
            return;
        }

        // 세로 검사
        for(int i = 0; i < 3; i++) {
            int tmpVal = 0;
            int[] tmp = new int[] {arr[0][i], arr[1][i], arr[2][i]};
            int min = Arrays.stream(tmp).min().getAsInt();
            for (int j = 0; j < 3; j++) {
                tmpVal += tmp[j] - min;
            }
            answer = Math.min(tmpVal, answer);
        }
        System.out.println(answer);

    }
}



테스트 케이스 4번, 8번이 자꾸 오답인데 어디에서 문제가 발생하는지 잘 모르겠습니다!

반례 알려주시면 감사하겠습니다!

#진정한_효도

이 카테고리의 톡 더보기