汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具。下面是c#实现汉诺塔示例
namespace 汉诺塔
{
class Program
{
static void hanoi(char A, char B, char C, int count)
{
if (count == 1)
Console.WriteLine("1: " + A + "->" + B);
else
{
hanoi(A, C, B, count - 1);
Console.WriteLine(count + ": " + A + "->" + B);
hanoi(C, B, A, count - 1);
}
}
static void Main(string[] args)
{
Console.WriteLine("请输入圆盘个数:");
int N = 0;
N = Convert.ToInt32(Console.ReadLine());
hanoi('A', 'B', 'C', N);
Console.WriteLine();
Console.ReadKey();
}
}
}
新闻热点
疑难解答