zoukankan      html  css  js  c++  java
  • 2015华硕”硕士生”笔试题(瓶子问题)

    饮料卖两块钱一瓶,两个空瓶子或者四个瓶盖均可以换一瓶新的饮料。10块钱可以喝多少瓶饮料?

        public static int getDrinkCount(int money ,int price){
            int bottleCount = 2;
            int capCount = 4;
            int bottle = 0;
            int cap = 0;
            int drinkCount = 0;
            
            drinkCount = money / price;
            bottle = drinkCount ;
            cap = drinkCount ;
            return getDrinkCount(drinkCount, bottle, cap, bottleCount, capCount);
        }
        
        private static int getDrinkCount(int drinkCount,int bottle,int cap ,int bottleCount,int capCount){
            
            int count = bottle / bottleCount + cap / capCount;
            drinkCount += count;
            bottle = bottle % bottleCount + count;
            cap = cap % capCount + count;
            System.out.println(count +"=="+bottle +"=="+cap);
            if (bottle < bottleCount && cap < capCount) {
                return drinkCount;
            }
            return getDrinkCount(drinkCount, bottle, cap, bottleCount, capCount);
        }
  • 相关阅读:
    如何在Linux下的C++文件使用GDB调试
    21天学通C++(C++程序的组成部分)
    嵌入式Linux应用程序开发
    项目部署的问题
    未解决
    报错
    随笔
    逆向工程出现的错误1
    jpa学习
    springmvc整合mybaits
  • 原文地址:https://www.cnblogs.com/phyxis/p/5250340.html
Copyright © 2011-2022 走看看