62,254
社区成员
发帖
与我相关
我的任务
分享
private int count = 22;
static void Main(string[] args)
{
Program program = new Program();
program.Count(program.count);
Console.WriteLine("一共能喝" + program.count.ToString() + "瓶水");
}
/// <summary>
/// 计算方法
/// </summary>
/// <param name="x"></param>
private void Count(int x)
{
if (x > 3)
{
int age = x / 3;//获得能换多少个水
int temp = x % 3;//获不能换余下来的瓶子
count = count + age;
Count(age + temp);
}
}
private int test(int sum)
{
int i = 0;
int tempNumber = 0;
while (sum + tempNumber >= 3)
{
i += sum;
sum += tempNumber;
tempNumber = sum % 3;
sum = sum / 3;
}
return i;
}
Module Module1
Dim count As Integer = 0
Dim empty As Integer = 0
Sub Main()
Drink(100)
Console.ReadKey()
End Sub
Sub Drink(ByVal bottle As Integer)
Dim wine = bottle \ 3
empty = ((bottle Mod 3) + wine)
count += wine
Console.WriteLine("换来了{0}瓶酒", wine)
If empty < 3 Then Exit Sub
Drink(empty)
End Sub
End Module
//32 剩2个
public int money = 22;
protected void Page_Load(object sender, EventArgs e)
{
int result = 0;
int pingzi = 0;
Count(ref result, ref pingzi);
Response.Write(result + "=" + pingzi);
}
public void Count(ref int result, ref int pingzi)
{
money--;
result++;
pingzi++;
if (pingzi % 3 == 0)
{
money++;
pingzi = 0;
}
if (money > 0)
Count(ref result, ref pingzi);
}

//每三个空酒瓶换一瓶酒,编写 要求参数为有多少个空酒瓶,最后返回能喝多少瓶酒。
void GetWinebottleNumber(int bottleNumber)
{
int iResult = 0,iTemp = 0;
//iResult += bottleNumber;
do
{
iTemp = bottleNumber/3;
iResult += iTemp;
bottleNumber = bottleNumber % 3 + iTemp;
}
while(bottleNumber>=3);
CString strResult;
strResult.Format(_T("喝%d余%d"),iResult,bottleNumber);
MessageBox(NULL,strResult,NULL,MB_OK);
}
protected void test(int num) // num是空瓶的数量
{
int result = 0;
while (num / 3 > 0)
{
result = result + (int)num / 3;
num = (int)num / 3 + num % 3;
}
Response.Write(result);
}