🌕🌗🌑🌑🌑

# 題目連結

  • 題目連結
  • Online Judge
  • uDebug

# 題目說明

Time limit: 3.000 seconds

# 題目

Ivan works at a factory that produces heavy machinery. He has a simple job — he knocks up wooden boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular parallelepiped. Ivan uses six rectangular wooden pallets to make a box. Each pallet is used for one side of the box.

Imgur

Joe delivers pallets for Ivan. Joe is not very smart and often makes mistakes — he brings Ivan pallets that do not fit together to make a box. But Joe does not trust Ivan. It always takes a lot of time to explain Joe that he has made a mistake.

Fortunately, Joe adores everything related to computers and sincerely believes that computers never make mistakes. Ivan has decided to use this for his own advantage. Ivan asks you to write a program that given sizes of six rectangular pallets tells whether it is possible to make a box out of them.

# Input

Input file contains several test cases. Each of them consists of six lines. Each line describes one pallet and contains two integer numbers w and h (1 ≤ w, h ≤ 10 000) — width and height of the pallet in millimeters respectively.

# Output

For each test case, print one output line. Write a single word ‘POSSIBLE’ to the output file if it is possible to make a box using six given pallets for its sides. Write a single word ‘IMPOSSIBLE’ if it is not possible to do so.

# Sample Input

1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234

# Sample Output

POSSIBLE
IMPOSSIBLE

# 解題技巧

# Solution

Main.java
import java.util.*;
class Box {
    public int x, y;
    public Box(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            Box[] box = new Box[6];
            for (int i = 0; i < 6; i++) {
                int L = sc.nextInt();
                int W = sc.nextInt();
                box[i] = new Box(Math.max(L, W), Math.min(L, W));
            }
            Arrays.sort(box, new Comparator<Box>() {
                @Override
                public int compare(Box a, Box b) {
                    if (a.x == b.x)
                        return a.y - b.y;
                    return a.x - b.x;
                }
            });
            boolean isBox = false;
            if (box[0].y == box[1].y && box[1].y == box[2].y && box[2].y == box[3].y
                    && box[2].x == box[3].x && box[3].x == box[4].x && box[4].x == box[5].x
                    && box[0].x == box[1].x && box[1].x == box[4].y && box[4].y == box[5].y) {
                isBox = true;
            }
            System.out.println(isBox ? "POSSIBLE" : "IMPOSSIBLE");
        }
        sc.close();
    }
}
單字

** **
!! !!

片語 & 搭配詞

!! !!