您的位置:首页 > 编程语言 > C#

C# 酒鬼买酒喝,瓶盖和空瓶子可以换新的酒

2016-02-16 17:42 288 查看




 

 

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();
}
}
}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: