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

posted @ 2016-02-16 17:42  盘子脸  阅读(748)  评论(0编辑  收藏  举报