zoukankan      html  css  js  c++  java
  • 一个数学题目的小小算法

    啤酒2块钱一瓶,

    4个盖子换一瓶;

    2个空瓶换一瓶;10块钱你能喝多少瓶啤酒???

        static void Main(string[] args)
           {
             pijiu(12);
          }
    
           static int temp_pj = 0;//喝啤酒数
            static int temp_gz = 0;//盖子
            static int temp_pz = 0;//空瓶
    
            public static int pijiu(int count)
            {
                int price = 2;
    
                temp_pj = temp_gz = temp_pz = count / price;//第一次
    
                while (Sum() != 0)
                {
                    Sum();
                }
    
                return temp_pj;
            }
    
            public static int Sum()
            {
                int pj = 0;
    
                while ((temp_pz / 2) > 0)
                {
                    pj = pj + 1;
                    temp_gz = temp_gz + 1;
                    temp_pz = temp_pz - 2;//2个空瓶子换一瓶
                    temp_pz = temp_pz + 1;//换一瓶酒 多一个空瓶
                }
    
                while ((temp_gz / 4) > 0)
                {
                    pj = pj + 1;
                    temp_gz = temp_gz - 4;//4个盖子换一瓶
                    temp_pz = temp_pz + 1;
                    temp_gz = temp_gz + 1;//换一瓶酒 多一个盖子
                }
    
                temp_pj = temp_pj + pj;
    
                return pj;
            }
    View Code

    手算 和算法 10块钱 都是15瓶;12块钱 能喝19瓶;

    对吗? 求指导

    ----------------------------------------------------------------------------

    请关注我的微信公众号!o(∩_∩)o 哈哈

  • 相关阅读:
    数码摄影技巧拍摄的基本概念
    数码相机摄影技巧入门
    linux syslog用法
    委托
    创建遮罩层
    通过javascript获取多种主流浏览器显示页面高度
    sql 工具文件
    正则表达试笔记
    过滤字符串中带的HTML代码
    分页程序
  • 原文地址:https://www.cnblogs.com/amoshu/p/5036361.html
Copyright © 2011-2022 走看看