Tower C and Tower C

Source: Internet
Author: User

Tower C and Tower C
/* Tower play: * game rule: Move the plate on column A to column C, and the tray must be on a small disk. * 1 when there is only one plate on column A, move it directly to column C; * 2 when there are two plates on column A, * move one disk on column A (numbered from top to bottom) move Column B, * move two disks on column A to column C, * move one disk on column B to column C. * (move 1 to column ~ N-1 disk ----> Column B, place column A n ----> column C, column B 1 ~ N-1 disk ----> C column) * 3 when there are three plates on the column ~ 2 disks move to Column B, * 3 disks on column A to column C, and * 1 to Column B ~ Move two disks to column C * (move 1 ~ N-1 disk ----> Column B, place column A n ----> column C, column B 1 ~ N-1-1 Disk ----> C column) * n when there are n plates on column A, 1 ~ N-1 disk is moved to Column B, * n disk on column A is moved to column C, and * 1 ~ N-1-1 disk is moved to the C-column. * (Set 1 ~ N-1 disk ----> Column B, place column A n ----> column C, column B 1 ~ N-1 disk ----> C column )**/

 1 #include<stdio.h> 2   3 void Hanoi(int count,char a,char b,char c){ 4 if(count == 1){ 5 printf("FROM %c TO %c\n",a,c); 6 }else 7 { 8 Hanoi(count-1,a,c,b); 9 printf("FROM %c TO %c\n",a,c);10 Hanoi(count-1,b,a,c);11 }12 }13 int main(){14 printf("please input the number of Hanoi:");15 int n;16 scanf("%d",&n);17 Hanoi(n,'A','B','C');18 return 0;19 }

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.