[DRAWRECT] 질문입니다.

  • fly0159
    fly0159

    저의 알고리즘은 이렇습니다.

    1. 데이터 입력
    2. 각 좌표의 숫자 카운트
    3. 숫자 중 카운트가 1인 값이 결과

    알고 스팟 기본 예제는 넣어봤는데 잘나옵니다.
    근데 답안 제출하면 오답이라고 나오네요.

    import java.util.Scanner;

    public class Main {
    final static int THREE = 3;
    final static int MIN = 1;
    final static int MAX = 1000;

    public static void main(String[] args) {
        System.out.println("Input testCase");
    
        Scanner s = new Scanner(System.in);
        int testCase = s.nextInt();
    
        int[][] coordinateX = new int[testCase][THREE];
        int[][] coordinateY = new int[testCase][THREE];
    
        for (int i = 0; i < testCase; i++) {
            System.out.println("Input " + i + " coordinate (x y)");
    
            for (int j = 0; j < THREE; j++) {
    
                coordinateX[i][j] = s.nextInt();
                coordinateY[i][j] = s.nextInt();
                // space로 구분 됨.
    
                if ((coordinateX[i][j] <= MIN || coordinateX[i][j] >= MAX)
                        || (coordinateY[i][j] <= MIN || coordinateY[i][j] >= MAX)) {
                    System.out.println("input is bad scope");
                    return;
                }// 범위
    
            }// end for j
    
        }// end for testCase
        calculation(coordinateX, coordinateY, testCase);
    
    }// end main
    
    private static void calculation(int[][] coordinateX, int[][] coordinateY,
            int testCase) {
    
        for (int i = 0; i < testCase; i++) {
    
            int[] cntX = new int[2];
            int[] cntY = new int[2];
            int[] resultX = new int[2];
            int[] resultY = new int[2];
    
            for (int j = 0; j < THREE; j++) {
    
                if (coordinateX[i][0] == coordinateX[i][j]) {
                    cntX[0]++;
                    resultX[0] = coordinateX[i][j];
                } else {
                    cntX[1]++;
                    resultX[1] = coordinateX[i][j];
                }
    
                if (coordinateY[i][0] == coordinateY[i][j]) {
                    cntY[0]++;
                    resultY[0] = coordinateY[i][j];
                } else {
                    cntY[1]++;
                    resultY[1] = coordinateY[i][j];
                }
    
            }// end for j
    
            if (cntX[0] == 1) {
                System.out.print(resultX[0] + " ");
            } else {
                System.out.print(resultX[1] + " ");
            }
    
            if (cntY[0] == 1) {
                System.out.println(resultY[0]);
            } else {
                System.out.println(resultY[1]);
            }
    
        }// end for testCase
    
    }// end calculation

    }


    8년 전
0개의 댓글이 있습니다.
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.