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";
    }
};
相关推荐
ChoSeitaku13 分钟前
链表循环及差集相关算法题|判断循环双链表是否对称|两循环单链表合并成循环链表|使双向循环链表有序|单循环链表改双向循环链表|两链表的差集(C)
c语言·算法·链表
娅娅梨15 分钟前
C++ 错题本--not found for architecture x86_64 问题
开发语言·c++
DdddJMs__13518 分钟前
C语言 | Leetcode C语言题解之第557题反转字符串中的单词III
c语言·leetcode·题解
兵哥工控19 分钟前
MFC工控项目实例二十九主对话框调用子对话框设定参数值
c++·mfc
Fuxiao___22 分钟前
不使用递归的决策树生成算法
算法
我爱工作&工作love我27 分钟前
1435:【例题3】曲线 一本通 代替三分
c++·算法
娃娃丢没有坏心思1 小时前
C++20 概念与约束(2)—— 初识概念与约束
c语言·c++·现代c++
lexusv8ls600h1 小时前
探索 C++20:C++ 的新纪元
c++·c++20
lexusv8ls600h1 小时前
C++20 中最优雅的那个小特性 - Ranges
c++·c++20
白-胖-子1 小时前
【蓝桥等考C++真题】蓝桥杯等级考试C++组第13级L13真题原题(含答案)-统计数字
开发语言·c++·算法·蓝桥杯·等考·13级