当前位置:网站首页>"Fundamentals of program design" Chapter 10 function and program structure 7-2 Hanoi Tower problem (20 points)
"Fundamentals of program design" Chapter 10 function and program structure 7-2 Hanoi Tower problem (20 points)
2022-07-21 11:34:00 【Cha ran o】
There is a Vatican Pagoda in an ancient temple , There is... In the tower 3 Seats A、B and C, seat A On top of it 64 Disks of different sizes , The market is under , Small in . There is a monk who wants to 64 A disc from the seat A Move to seat B, But you can only move one plate at a time , The moving disc is only allowed to be placed on the other two seats , And the market cannot be pressed on the small market . Now it is required to simulate the process with a program , Enter a positive integer n, Represents the number of plates , Write function
void hanoi(int n,char a,char b,char c)
among ,n Count the plates , from a Seat to b seat ,c The seat serves as an intermediate transition , The function of this function is to output the path of moving the plate .
Input format :
Enter... On one line 1 A positive integer n.
Output format :
Output moving plate path .
sample input :
3
No blank lines at the end
sample output :
a-->b
a-->c
b-->c
a-->b
c-->a
c-->b
a-->b
No blank lines at the end
#include<stdio.h>
#include<stdlib.h>
void hanio(int n,char a,char b,char c);
int main()
{
int n=0;
scanf("%d",&n);
hanio(n,'a','b','c');
return 0;
}
void hanio(int n,char a,char b,char c)
{
if(n==1)
printf("%c-->%c\n",a,b);
else{
hanio(n-1,a,c,b);
printf("%c-->%c\n",a,b);
hanio(n-1,c,b,a);
}
}
边栏推荐
猜你喜欢
sqlilabs less-25~25a
Detailed explanation of redis cluster construction and configuration optimization
Kettle Job实现每6s就运行一个Kettle的转换任务
JD cloud and Forrester consulting released a hybrid cloud report that cloud Nativity has become a new engine driving industrial development
uniapp小程序增加自定义复选框样式
2021-9-18
Acmstreamopen return value problem
试着换个角度理解低代码平台设计的本质
使用Kettle读取Excel文件中的数据,存储在MySQL中
【愚公系列】2022年7月 Go教学课程 013-常量、指针
随机推荐
416. 分割等和子集
Shandong University, Beijing post, Harbin Institute of technology | multimodal dialog systems with dual knowledge enhanced generic trained language model
进程/线程同步机制
Wpf 多指应用开发解析
Acmstreamopen return value problem
【无标题】
消防安全不能忘!广州这11处场所存在火灾隐患
执行ls /dev/pts为什么这么慢?
Network Security Learning (IX) comprehensive experiment & PKI
建议收藏 | 可实操,数据中台选型示例
Advantages of stable tripartite payment channels
《程序设计基础》 第十章 函数与程序结构 6-7 判断满足条件的三位数 (15 分)
网络安全学习(五)DHCP
关于常量修饰符 const
微信小程序 04 路由跳转和生命周期函数
OptaPlanner 发展方向与问题
腾讯音视频服务的使用体验
DEBUG:Generate Bitstream失败
unity texturestreaming
Musk: I uploaded my brain to the cloud. Sorry, 404