C++ - 汉诺塔
分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net
/** Created by Chimomo*/#include <iostream>using namespace std;void print(char A, char C) {cout << A << " --> " << C << endl;}void hanoi(int n, char A, char B, char C) {if (n == 1) {print(A, C);} else {hanoi(n - 1, A, C, B);print(A, C);hanoi(n - 1, B, A, C);}}int main() {int n;cout << "Please input the number of plates in pile A:";cin >> n;hanoi(n, 'A', 'B', 'C');return 0;}// Output:/*Please input the number of plates in pile A:66A --> BA --> CB --> CA --> BC --> AC --> BA --> BA --> CB --> CB --> AC --> AB --> CA --> BA --> CB --> CA --> BC --> AC --> BA --> BC --> AB --> CB --> AC --> AC --> BA --> BA --> CB --> CA --> BC --> AC --> BA --> BA --> CB --> CB --> AC --> AB --> CA --> BA --> CB --> CB --> AC --> AC --> BA --> BC --> AB --> CB --> AC --> AB --> CA --> BA --> CB --> CA --> BC --> AC --> BA --> BA --> CB --> CB --> AC --> AB --> CA --> BA --> CB --> C*/
赞 (0)