Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int hanoi(int n,char from, char mid,char to,int* pCounter)
- {
- if(n==0)
- {return;}
- hanoi(n-1,from, to, mid,pCounter);
- //printf("圓盤%2d移動%d次\n",n,counter);
- pCounter[n-1]++;
- printf("plate%2d from %c -> %c\n",n,from,to,pCounter);
- hanoi(n-1,mid, from, to,pCounter);
- }
- int main()
- {
- int n;
- int pCounter[100]={0};
- scanf("%d",&n);
- hanoi(n,'A','B','C',pCounter);
- printf ("\n");
- int i;
- for (i=0;i<n;i++)
- {
- printf("plate %d = %d\n",i+1,pCounter[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement