题解 | #汽水瓶#

汽水瓶

https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f

#include <stdio.h>


int getDrinkB(int numAll)
{
    int drinkCount = 0;
    int leftNum = numAll;
    int currentDrink = 0;
    while(leftNum >= 3)
    {   
        currentDrink = leftNum / 3;
        drinkCount += currentDrink;
        leftNum = currentDrink + leftNum % 3;
        currentDrink = 0;
    }

    if(leftNum == 2)
        drinkCount++;
    return drinkCount;
}

int main() {
    int num = 0;
    int drinkCount = 0;
    int ret = scanf("%d",&num);
    while(0 != num && EOF != ret)
    {
        printf("%d\n",getDrinkB(num));
        ret = scanf("%d",&num);
    }

    return 0;
}

全部评论

相关推荐

10-09 09:39
门头沟学院 C++
HHHHaos:这也太虚了,工资就一半是真的
点赞 评论 收藏
分享
11-05 07:29
贵州大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务