Created
December 26, 2019 13:00
-
-
Save listopad/a72280166ea821a92187d52aca32ff05 to your computer and use it in GitHub Desktop.
Задача A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void CheckBoxEquality(int a1, int b1, int c1, int a2, int b2, int c2) { | |
/* | |
Идея: решение довольно очевидное, по сути нам нужно просто упорядочить размеры каждой коробки, чтобы A <= B <= C. | |
Дальше проверяем все четыре случая: | |
1. A1 >= A2, B1 >= B2, C1 >= C2 - первая коробка больше второй | |
2. A1 <= A2, B1 <= B2, C1 <= C2 - первая коробка меньше второй | |
2. A1 == A2, B1 == B2, C1 == C2 - коробки одинаковы | |
4. Если первые три случая не выполняются значит коробки не совместимы. | |
*/ | |
//sort first box | |
int min = a1; | |
int max = c1; | |
if (min > b1) min = b1; | |
if (min > c1) min = c1; | |
if (min < a1) max = a1; | |
if (max < b1) max = b1; | |
b1 = a1 + b1 + c1 - min - max; | |
a1 = min; | |
c1 = max; | |
//sort second box | |
min = a2; | |
max = c2; | |
if (min > b2) min = b2; | |
if (min > c2) min = c2; | |
if (min < a2) max = a2; | |
if (max < b2) max = b2; | |
b2 = a2 + b2 + c2 - min - max; | |
a2 = min; | |
c2 = max; | |
//check result | |
if ((a1 == a2) && (b1 == b2) && (c1 == c2)) | |
System.out.println("Boxes are equal"); | |
else if ((a1 <= a2) && (b1 <= b2) && (c1 <= c2)) | |
System.out.println("The first box is smaller than the second one"); | |
else if ((a1 >= a2) && (b1 >= b2) && (c1 >= c2)) | |
System.out.println("The first box is larger than the second one"); | |
else | |
System.out.println("Boxes are incomparable"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment