LeetCode每日一题——2525. Categorize Box According to Criteria

文章目录

一、题目

Given four integers length, width, height, and mass, representing the dimensions and mass of a box, respectively, return a string representing the category of the box.

The box is "Bulky" if:

Any of the dimensions of the box is greater or equal to 104.

Or, the volume of the box is greater or equal to 109.

If the mass of the box is greater or equal to 100, it is "Heavy".

If the box is both "Bulky" and "Heavy", then its category is "Both".

If the box is neither "Bulky" nor "Heavy", then its category is "Neither".

If the box is "Bulky" but not "Heavy", then its category is "Bulky".

If the box is "Heavy" but not "Bulky", then its category is "Heavy".

Note that the volume of the box is the product of its length, width and height.

Example 1:

Input: length = 1000, width = 35, height = 700, mass = 300

Output: "Heavy"

Explanation:

None of the dimensions of the box is greater or equal to 104.

Its volume = 24500000 <= 109. So it cannot be categorized as "Bulky".

However mass >= 100, so the box is "Heavy".

Since the box is not "Bulky" but "Heavy", we return "Heavy".

Example 2:

Input: length = 200, width = 50, height = 800, mass = 50

Output: "Neither"

Explanation:

None of the dimensions of the box is greater or equal to 104.

Its volume = 8 * 106 <= 109. So it cannot be categorized as "Bulky".

Its mass is also less than 100, so it cannot be categorized as "Heavy" either.

Since its neither of the two above categories, we return "Neither".

Constraints:

1 <= length, width, height <= 105

1 <= mass <= 103

二、题解

cpp 复制代码
class Solution {
public:
    string categorizeBox(int length, int width, int height, int mass) {
        bool isBulky = false,isHeavy = false;
        long long V = (long long)length * width * height;
        if(length >= pow(10,4) || width >= pow(10,4) || height >= pow(10,4) || V >= pow(10,9)) isBulky = true;
        if(mass >= 100) isHeavy = true;
        if(isBulky && isHeavy) return "Both";
        else if(!isBulky && !isHeavy) return "Neither";
        else if(isBulky && !isHeavy) return "Bulky";
        else return "Heavy";
    }
};
相关推荐
恒者走天下13 分钟前
秋招是开发算法一起准备,还是只准备一个
c++
charlie11451419121 分钟前
从C++编程入手设计模式——外观模式
c++·设计模式·外观模式
虾球xz32 分钟前
CppCon 2016 学习:The Exception Situation
开发语言·c++·学习
老土豆FUSK34 分钟前
C++ 封装特性
开发语言·c++
蒙奇D索大37 分钟前
【数据结构】图论实战:DAG空间压缩术——42%存储优化实战解析
数据结构·笔记·学习·考研·图论·改行学it
Cyrus_柯1 小时前
C++(面向对象编程)
开发语言·c++·算法·面向对象
wen__xvn1 小时前
九日集训第六天
数据结构·算法·leetcode
梦境虽美,却不长4 小时前
C++ 学习 多线程 2025年6月17日18:41:30
c++·学习·线程·异步
eyexin20184 小时前
大模型量化与剪枝
算法·机器学习·剪枝
一只理智毅4 小时前
copy-and-swap语义
c++