首页 > 携程笔试10月13日(三题:100%,0,%45)
头像
Sun浅雨
编辑于 2020-10-13 14:19
+ 关注

携程笔试10月13日(三题:100%,0,%45)

第一题:100%
int buyCoke(int m, int a, int b, int c, int x) {
    int res = 0;

    while(m > 0) {
        if (c > 0 && c * 100 >= x) {
            c -= x / 100;
            res += x / 100;
            if (x % 100 != 0) {
                c -= 1;
                res++;
            }
            b += x % 100 / 50;
            a += x % 100 % 50 / 10;

        } else if (b > 0 && c * 100 + b * 50 >= x) {
            b -= (x - c * 100) / 50;
            res += (x - c * 100) / 50;
            res += c;
            if ((x - c * 100) % 50 != 0) {
                b -= 1;
                res++;
            }

            c = 0;
            a += (x - c * 100) % 50 / 10;

        } else if (a > 0 && b * 50 + a * 10 >= x) {
            a -= (x - b * 50) / 10;
            res += (x - b * 50) / 10;
            res += b;

            b = 0;
        }
        m--;
    }
    return res;
}

第二题:没做

第三题:return 0;  45%


全部评论

(3) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

历年真题 真题热练榜 24小时
技术(软件)/信息技术类
查看全部

近期精华帖

热门推荐