知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

  • 练习题

    • 选择题 & 填空题

    • 代码题

      • Boxes
        • Topic
        • Problem
        • Solutions
          • Other solution 1
          • Other solution 2
      • The longest ascending sequence
      • Right Rotation
      • Book
      • Compact strings with AsciiCharSequence
      • Cinema
      • Calculate square
      • Count words
      • Robot control
      • Concat all strings without digits
      • Find the nearest number
      • Leaderboard
      • Split a list into sublists
      • Arithmetic average
      • Processing strings
  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • 练习题
  • 代码题
Jim
2022-04-29
目录

Boxes

# Topic

Iterating over arrays

# Problem

Boxes

There are two boxes on the table. The first box has a size of X1 x Y1 x Z1, and the second box has a size of X2 x Y2 x Z2. You need to determine whether one of the boxes can be put inside the other. It should go in without sticking out. You can rotate both boxes as you want.

Important: two equally sized boxes cannot be placed inside one another. See the third test case as an example of how the borderline case should be treated.

Input consists of two lines:

  • the first line contains numbers X1, Y1, Z1;
  • the second line contains numbers X2, Y2, Z2.

All numbers are integers and greater than 0.

Output:

  • "Box 1 < Box 2", if the first box can be put inside the second box ;
  • "Box 1 > Box 2", if the second box can be put inside the first box;
  • otherwise, output "Incompatible".

Sample Input 1:

1 2 3
5 6 4
1
2

Sample Output 1:

Box 1 < Box 2
1

Sample Input 2:

2 9 4
3 8 1
1
2

Sample Output 2:

Box 1 > Box 2
1

Sample Input 3:

1 3 7
2 8 3
1
2

Sample Output 3:

Incompatible
1

# Solutions

# Other solution 1

import java.util.Scanner;
import java.util.Arrays;

class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int[] box1 = new int[3];
        int[] box2 = new int[3];
        int countA = 0;
        int countB = 0;

        for (int i = 0; i < 3; i++) {
            box1[i] = scanner.nextInt();
        }

        for (int i = 0; i < 3; i++) {
            box2[i] = scanner.nextInt();
        }

        Arrays.sort(box1);
        Arrays.sort(box2);

        for (int i = 0; i < 3; i++) {
            if (box1[i] < box2[i]) {
                countA++;
            } else if (box1[i] > box2[i]) {
                countB++;
            }
        }

        if (countA == 3) {
            System.out.println("Box 1 < Box 2");
        } else if (countB == 3) {
            System.out.println("Box 1 > Box 2");
        } else {
            System.out.println("Incompatible");
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

# Other solution 2

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        List<Integer> box1 = new ArrayList<>();
        box1.add(scanner.nextInt());
        box1.add(scanner.nextInt());
        box1.add(scanner.nextInt());

        List<Integer> box2 = new ArrayList<>();
        box2.add(scanner.nextInt());
        box2.add(scanner.nextInt());
        box2.add(scanner.nextInt());

        Collections.sort(box1);
        Collections.sort(box2);

        boolean box1Huge = box1.get(0) > box2.get(0) && box1.get(1) > box2.get(1) && box1.get(2) > box2.get(2);
        boolean box2Huge = box1.get(0) < box2.get(0) && box1.get(1) < box2.get(1) && box1.get(2) < box2.get(2);

        System.out.println(box1Huge ? "Box 1 > Box 2" :
                           box2Huge ? "Box 1 < Box 2" : "Incompatible");

    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
编辑 (opens new window)
#Java#Array#Problem
上次更新: 2022/09/25, 10:41:23
The number of insertions
The longest ascending sequence

← The number of insertions The longest ascending sequence→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式