2020京东实习生笔试,给定6组长(w)和宽(h),判断是否可以组成长方体

渣渣只能写成这样,希望有大佬能纠正一下~
输入:
2
1 4
1 4
2 8
2 8
9 1
9 1
1 4
1 4
1 4
1 4
1 4
1 4
输出:
POSSIBLE
POSSIBLE

import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            int n = sc.nextInt();
            int [][][] num = new int[n][6][2];
            for (int i=0;i<n;i++) {
                for (int j=0;j<6; j++) {
                    num[i][j][0] = sc.nextInt();
                    num[i][j][1] = sc.nextInt();
                }
            }
/*                for (int j=0;j<6;j++) {
                    for (int k=0;k<2;k++) {
                        System.out.print(num[0][j][k]+" ");
                    }
                System.out.println();
            }*/
            for (int i=0;i<n;i++) {
                for (int j=0;j<6;j++) {
                    if (num[i][j][0] >= num[i][j][1]) {
                        int tem = num[i][j][0];
                        num[i][j][0] = num[i][j][1];
                        num[i][j][1] = tem;
                    }
                }
            }

            for (int i=0;i<n;i++) {
                if (num[i].length!=6||num[i][0].length!=2) {
                    System.out.println("IMPOSSIBLE");
                    return;
                }
                isRectangle(num[i]);
            }
        }
        sc.close();
    }

    static void isRectangle(int[][] arr){
        Set<String> set = new HashSet<>();
        for (int i=0;i<arr.length;i++) {
            set.add(arr[i][0]+" "+ arr[i][1]);
        }
        if (set.size() == 1) {
            System.out.println("POSSIBLE");
        } else if (set.size() == 2) {
            System.out.println("POSSIBLE");
        } else if (set.size() == 3) {
            System.out.println("POSSIBLE");
        }else System.out.println("IMPOSSIBLE");
    }
}

你可能感兴趣的:(算法)