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

2023-01-04,

 

 

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

C# 酒鬼买酒喝,瓶盖和空瓶子可以换新的酒的相关教程结束。

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

下载本文的Word格式文档,以方便收藏与打印。