개발자 톡

연습문제 톡 진정한 효도

테케 4번..

등록일
2024-02-02 12:28:25
조회수
389
작성자
chaesc1223
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int[][] map = new int[3][3];

        StringTokenizer st;
        for(int i=0; i<3; i++) {
            st = new StringTokenizer(br.readLine());
            for(int j=0; j<3; j++){
                map[i][j] = Integer.parseInt(st.nextToken());
            }
        }
        ArrayList<Integer> list = new ArrayList<>();
        //가로 체크
        for(int i=0; i<3; i++) {
            int[][] copy = map.clone();
            int sum1 = 0;
            for(int j=1; j<3; j++) {
                Arrays.sort(copy,(o1,o2) -> o1[0] - o2[0]);
                sum1 += Math.abs(copy[i][j-1] - copy[i][j]); //가로
            }
            list.add(sum1);
        }
        for(int i=0; i<3; i++) {
            int sum2 = 0;
            for(int j=1; j<3; j++) {
                Arrays.sort(map,(o1,o2) -> o1[1] - o2[1]);
                sum2 += Math.abs(map[j-1][i] - map[j][i]); //세로
            }
            list.add(sum2);
        }
        Collections.sort(list);
        System.out.println(list.get(0));
        
    }
}

4번만 틀리는데 반례 있을까요?ㅠㅠ

#진정한_효도

이 카테고리의 톡 더보기