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";
    }
};
相关推荐
Irissgwe11 小时前
c++类型转换
c++·类型转换·explicit·static_cast·const_cast·dynamic_cast·rtti
智者知已应修善业11 小时前
【51单片机用T0定时器方式1,实现0.5S的时间间隔实现第一次一个灯亮、第二次二个灯亮,直到全部灯亮,然后重复整个过程】2023-12-29
c++·经验分享·笔记·算法·51单片机
小许同学记录成长12 小时前
几何体编辑与布尔运算
算法·无人机
fanged12 小时前
简单看看3A算法2(TODO)
算法
智者知已应修善业12 小时前
【51单片机4位静态数码管显示1234】2023-11-14
c++·经验分享·笔记·算法·51单片机
抓虾爪12 小时前
ST意法代理商粤科源兴丨LSM6DS3全系列现货库存,LSM6DS3TR-C当天可发
c++
♡すぎ♡12 小时前
镜面 IBL 预过滤贴图的计算
算法·计算机图形学·贴图·pbr
妙为12 小时前
unreal engine5.7.4,创建ThirdPerson第三人称模版,类型是c++崩溃
c++·ue5·虚幻·unreal engine5
郝学胜_神的一滴12 小时前
Qt 高级开发 021:零基础吃透 QVBoxLayout 垂直布局
c++·qt
Lsk_Smion12 小时前
力扣实训 _ [200].岛屿数量
算法·leetcode·深度优先