标签:des style blog io color ar os sp div
2
Move disk 1 from A to B Move disk 2 from A to C Move disk 1 from B to C
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
void hanoi(int n, char a, char b, char c )
{
if(n==1)
{
printf("Move disk %d from %c to %c\n", n, a, c);
}
else
{
hanoi(n-1, a, c, b);
printf("Move disk %d from %c to %c\n", n, a, c );
hanoi(n-1, b, a, c);
}
}
int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
hanoi(n, ‘A‘, ‘B‘, ‘C‘);
}
return 0;
}
标签:des style blog io color ar os sp div
原文地址:http://www.cnblogs.com/yspworld/p/4090825.html