posts - 930,  comments - 588,  views - 402万
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

第一次用word 2007POST

/// <summary>

/// 两个小孩去打油,一人带了一个一斤的空瓶,另一个带了一个七两和一个三两的空瓶。

/// 原计划各打一斤油,可是由于所带的钱不够,只好合打了一斤油,

/// 在回家的路上,二人想平分这一斤油,可是又没有其它工具。

/// 现只用这三个瓶子(一斤、七两、三两)精确地分出两个半斤油来。

/// </summary>

/// <remarks>author petter liu 2008726</remarks>

[TestFixture]

public class Testnkap

{

private int a10 = 10;

private int a7 = 0;

private int a3 = 0;

private int count = 0;

 

/// <summary>

/// fenyou

/// <remarks>

/// 5=3+25=7-2;关键是要多出一个2L的油,2L的空间。

/// </remarks>

/// </summary>

[Test]

public void fenyou()

{

Console.WriteLine("10->7");

swap(ref a10, ref a7, 7);

Console.WriteLine("7->3");

swap(ref a7, ref a3, 3);

Console.WriteLine("3->10");

swap(ref a3, ref a10, 3);

Console.WriteLine("7->3");

swap(ref a7, ref a3, 3);

Console.WriteLine("3->10");

swap(ref a3, ref a10, 3);

Console.WriteLine("7->3");

swap(ref a7, ref a3, 1);

Console.WriteLine("10->7");

swap(ref a10, ref a7, 7);

Console.WriteLine("7->3");

swap(ref a7, ref a3, 2);

Console.WriteLine("3->10");

swap(ref a3, ref a10, 3);

Console.ReadLine();

}

 

/// <summary>

/// 交换Function

/// </summary>

/// <param name="x">source</param>

/// <param name="y">target</param>

/// <param name="num">num</param>

private void swap(ref int x, ref int y, int num)

{

x = x - num;

y = y + num;

count++;

Console.WriteLine("{0}", count);

Console.WriteLine("{0} {1} {2}", a10, a7, a3);

Console.WriteLine("--------------------------");

}

}

输出结果:

10->7

第次

3 7 0

--------------------------

7->3

第次

3 4 3

--------------------------

3->10

第次

6 4 0

--------------------------

7->3

第次

6 1 3

--------------------------

3->10

第次

9 1 0

--------------------------

7->3

第次

9 0 1

--------------------------

10->7

第次

2 7 1

--------------------------

7->3

第次

2 5 3

--------------------------

3->10

第次

5 5 0

--------------------------

posted on   PetterLiu  阅读(537)  评论(1编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
点击右上角即可分享
微信分享提示