하노이탑

it/programming

' 하노이탑 ' 최단 이동 횟수를 구하라 - c++

#include "stdio.h" #include "stdlib.h" int h=0; void move(int from, int to) { printf("│ [%d]에서 [%d]으로 옮김 │\n", from, to); h++; } void hanoi(int n, int from, int by, int to) { if(n==1) { move(from,to); } else { hanoi(n-1,from,to,by); move(from,to); hanoi(n-1,by,from,to); } } void main(int n) { printf("탑이 몇층으로 이루어져 있습니까?\n▷ "); scanf("%d", &n); system("cls"); printf("\n\n┌────────────┐\n"); hanoi(..

반응형
훈솔
'하노이탑' 태그의 글 목록