Demo entry 6762981



Submitted by 反对法 on Oct 18, 2018 at 10:07
Language: C++. Code size: 511 Bytes.

#include <bits/stdc++.h>
using namespace std;

int step=0;
void dfs(int n,char A,char B,char C){
    if(n==0) return ;
    dfs(n-1,A,B,C);//将1~n-1的圆盘 从A柱 --> C柱
    printf("step %d : %c --> %c\n",++step,A,B);// n盘 从A柱 --> B柱
    dfs(n-1,C,B,A);//将1~n-1的圆盘 从C柱 --> A柱
    printf("step %d : %c --> %c\n",++step,B,C);// n盘 从B柱 --> C柱
    dfs(n-1,A,B,C);//将1~n-1的圆盘 从A柱 --> C柱
int main(){
    int n;
    char A='A',B='B',C='C';
    dfs(n,A,B,C);// 将编号1~n的圆盘 从A柱--> C柱
    return 0;

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).