Hi,
using System;
namespace Hanoi
{
class Solution
{
public static void doHanoi(int n, string f, string t, string u)
{
if (n <= 1)
{
System.Console.WriteLine(f + " --> " + t);
}
else
{
doHanoi(n - 1, f, u, t);
System.Console.WriteLine(f + " --> " + t);
doHanoi(n - 1, u, t, f);
}
}
[STAThread]
static void Main(string[] args)
{
if (args.Length != 1)
{
System.Console.WriteLine("usage: hanoi <number>");
System.Environment.Exit(1);
}
int n = System.Convert.ToInt32(args[0]);
if ((n < 1) || (n > 10))
{
System.Console.WriteLine("usage: hanoi <number> /* 1 <= number <= 10 */");
System.Environment.Exit(1);
}
doHanoi(n, "1", "3", "2");
System.Environment.Exit(0);
}
}
</number></number>