Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hanoi
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
int n = int.Parse(Console.ReadLine());
p.hanoi(n, 'A', 'C', 'B');
Console.ReadLine();
}
private void hanoi(int n, char s, char d, char t)
{
if (n == 1)
{ Console.Write("{0}->{1}\t", s, d); return; }
hanoi(n - 1, s, t,d);
Console.Write("{0}->{1}\t", s, d);
hanoi(n - 1, t, d,s);
return;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hanoi
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
int n = int.Parse(Console.ReadLine());
p.hanoi(n, 'A', 'C', 'B');
Console.ReadLine();
}
private void hanoi(int n, char s, char d, char t)
{
if (n == 1)
{ Console.Write("{0}->{1}\t", s, d); return; }
hanoi(n - 1, s, t,d);
Console.Write("{0}->{1}\t", s, d);
hanoi(n - 1, t, d,s);
return;
}
}
}
好无聊,看奥运的时候心血来潮,就写下来了。