leetcode_2525 根据规则将箱子分类

1. 题意

根据体积边长判断是否笨重,根据质量判读是否超重。
根据规则将箱子分类

2. 题解

直接判断即可,注意整形溢出应该使用long long

class Solution {
public:
    string categorizeBox(int length, int width, int height, int mass) {
        int v = 0;

        long long cap = (long long) length * width * height;
        if ( length >= 10000 || width >= 10000 || height >= 10000 || cap >= 1000000000)
            v |= 1;
        
        if ( mass >= 100)
            v |= 2;

        string attStr[] = { "Neither", "Bulky", "Heavy", "Both"};

        return attStr[v];

    }
};

你可能感兴趣的:(leetcode,c语言,leetcode,算法)