static未央

博客园 首页 新随笔 联系 订阅 管理
Hanoi
class Program
    {
        static long count = 0;
        static void move(char x, char y)
        {
            Console.WriteLine("{0}--->{1}", x, y);
        }
        static void hanoi(int n, char one, char two, char three)
        {

            if (n != 0)
            {
                hanoi(n - 1, one, three, two);
                move(one, two);
                hanoi(n - 1, three, two, one);
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            hanoi(n, 'A', 'B', 'C');
            Console.WriteLine("done,count:{0}", count);
            Console.Read();
        }
    }

 

posted on 2013-03-05 14:55  abstract未央  阅读(140)  评论(0编辑  收藏  举报