zoukankan      html  css  js  c++  java
  • C# 酒鬼买酒喝,瓶盖和空瓶子可以换新的酒

    )I1$KPJR1QNEK0M}W1Z4GDO

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace 换瓶子
    {
        class Program
        {
            //2元钱1瓶子
            //4个瓶盖换1瓶
            //2个空瓶子换1瓶
            //现在有10元钱,可以喝到几瓶
    
            static void Main(string[] args)
            {
                int drinkCount = 0;
                int 瓶子 = 10 / 2;
                int 盖子 = 10 / 2;
                int 换了几个瓶子 = 0;
                drinkCount += 瓶子;
    
    
                
    
                //开始继续换
                do
                {
                    //换盖子
                    if (盖子 >= 4)
                    {
                        换了几个瓶子 = 盖子 / 4;
    
                        盖子 = 盖子 % 4;
                        瓶子 += 换了几个瓶子;
                        盖子 += 换了几个瓶子;
    
                        drinkCount += 换了几个瓶子;
                    }
    
                    //换瓶子
                    if (瓶子 >= 2)
                    {
                        换了几个瓶子 = 瓶子 / 2;
                        瓶子 = 瓶子 % 2;
                        瓶子 += 换了几个瓶子;
                        盖子 += 换了几个瓶子;
    
                        drinkCount += 换了几个瓶子;
                    }
                } while (盖子 >= 4 || 瓶子 >= 2);
    
                if (盖子 < 4 && 瓶子 < 2)
                {
                    Console.WriteLine("喝了:" + drinkCount + "瓶子: " + 瓶子 + "盖子: " + 盖子);
                }
    
                Console.Read();
            }
        }
    }

    image

  • 相关阅读:
    Codevs堆练习
    codevs 3110 二叉堆练习3
    浅谈堆
    codevs 2924 数独挑战
    搜索技巧——持续更新
    2144 砝码称重 2
    codevs 2928 你缺什么
    codevs 2594 解药还是毒药
    codevs 2147 数星星
    判断素数
  • 原文地址:https://www.cnblogs.com/plateFace/p/5193449.html
Copyright © 2011-2022 走看看