汉诺塔问题: [STAThread] static void Main(string[] args) { // // TODO: 在此处添加代码以启动应用程序 // Console.WriteLine("**************************************************************"); Console.WriteLine("***** ****"); Console.WriteLine("******** put a on b with c **********"); Console.WriteLine("*************** *********************"); Console.WriteLine("**************************************************************"); Console.WriteLine("请输入盘的个数N:"); string a=Console.ReadLine(); int i; if(a.Length>0) { i=int.Parse(a);
HNT(i,"a","b","c"); } } public static void HNT(int i,string a,string b,string c) { if(i>0) { HNT(i-1,a,c,b); Console.WriteLine("将"+a+"放到"+b+"上"); HNT(i-1,c,b,a); } }
{
if(aa!=1)
{
aa(a-1);
}
return;
}Main()
{
aa(5);
}
汉诺塔问题:
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
// Console.WriteLine("**************************************************************");
Console.WriteLine("***** ****");
Console.WriteLine("******** put a on b with c **********");
Console.WriteLine("*************** *********************");
Console.WriteLine("**************************************************************");
Console.WriteLine("请输入盘的个数N:");
string a=Console.ReadLine();
int i;
if(a.Length>0)
{
i=int.Parse(a);
HNT(i,"a","b","c"); }
} public static void HNT(int i,string a,string b,string c)
{
if(i>0)
{
HNT(i-1,a,c,b);
Console.WriteLine("将"+a+"放到"+b+"上");
HNT(i-1,c,b,a);
}
}