fork download
  1. def move(n, a, b, c):
  2. if n == 1:
  3. print(a, '-->', c)
  4. else:
  5. move(n-1,a,c,b)
  6. print(a,'-->',c)
  7. move(n-1,b,a,c)
  8.  
  9. # 期待输出:
  10. # A --> C
  11. # A --> B
  12. # C --> B
  13. # A --> C
  14. # B --> A
  15. # B --> C
  16. # A --> C
  17. move(3, 'A', 'B', 'C')
  18.  
Success #stdin #stdout 0.07s 14180KB
stdin
Standard input is empty
stdout
A --> C
A --> B
C --> B
A --> C
B --> A
B --> C
A --> C