2525. 根据规则将箱子分类
1.题目介绍
2.题解(模拟)
2.1 思路
这题十分简单,唯一要注意的是length * height * width的运算结果(右边式子)默认是int类型,无法存储(不是说左边设置的变量是long long就行了,右边也要进行强制转换)
还有一个有趣的点就是这里对于
2.2 代码
class Solution {
public:
enum BoxCategory {
Neither,
Bulky,
Heavy,
Both,
Null
};
string categorizeBox(int length, int width, int height, int mass) {
long long volume = static_cast<long long>(length) * height * width;
BoxCategory category = Neither;
//这里 (long long)length * height * width >= 1e9 强制转换也可以
if (length >= 1e4 || width >= 1e4 || height >= 1e4 || volume >= 1e9)
category = Bulky;
if (mass >= 100)
category = static_cast<BoxCategory>(category | Heavy);
switch (category) {
case Neither: return "Neither";
case Bulky: return "Bulky";
case Heavy: return "Heavy";
case Both: return "Both";
case Null: return "Null";
default: return "Null";
}
}
};
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了