网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

c#的汉诺塔算法怎么写

这篇“c#的汉诺塔算法怎么写”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“c#的汉诺塔算法怎么写”文章吧。

创新互联公司专注于清水河企业网站建设,自适应网站建设,商城建设。清水河网站建设公司,为清水河等地区提供建站服务。全流程按需求定制网站,专业设计,全程项目跟踪,创新互联公司专业和态度为您提供的服务

#include 
void main()
{
  extern a;
  extern b;
  extern c;
  extern s;
  void hanno(int,char,char,char);
  void setNum(int);
  int n;
  printf("Please input the number of dishes: ");
  scanf("%d",&n);
  printf("The following is moving %d dishes ...\n             (%2d  0  0)\n",n,n);
  setNum(n);
  hanno(n,'A','B','C');
}
int a;
int b;
int c;
int s;
void setNum(int m)
{
  a=m;
}
void hanno(int m,char pillar1,char pillar2,char pillar3)
{
  void move(char,char,int);
  if(m==1) {
    s++;
    move(pillar1,pillar3,s);
  } else {
    hanno(m-1,pillar1,pillar3,pillar2);
    s++;
    move(pillar1,pillar3,s);
    hanno(m-1,pillar2,pillar1,pillar3);
  };
}
void move(char x,char y,int s)
{
  if (x=='A' && a>0 ) a--;
  else if (x=='B' && b>0 ) b--;
  else if (x=='C' && c>0 ) c--;
  
  if (y=='A') a++;
  else if (y=='B') b++;
  else if (y=='C') c++;
  printf("%3d: %c --> %c (%2d %2d %2d)\n",s,x,y,a,b,c);
}

#gcc hannuota.c -o hannuota

# ./hannuota
Please input the number of dishes: 3
The following is moving 3 dishes ...
             ( 3  0  0)

  1: A --> C ( 2  0  1)
  2: A --> B ( 1  1  1)
  3: C --> B ( 1  2  0)
  4: A --> C ( 0  2  1)
  5: B --> A ( 1  1  1)
  6: B --> C ( 1  0  2)
  7: A --> C ( 0  0  3)

以上就是关于“c#的汉诺塔算法怎么写”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注创新互联行业资讯频道。


网页标题:c#的汉诺塔算法怎么写
文章起源:http://bjjierui.cn/article/jpepsc.html

其他资讯