急求一道编程题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了急求一道编程题相关的知识,希望对你有一定的参考价值。

我表妹问我的,说是解决汉诺塔问题,求各位高手帮忙解决这个编程啊,谢谢了!!!!
最好用C或C++,其他语言也可以,但是一定要实现用动画来演示汉诺塔的移动,急求各位高手解决,急求!!!!
只是思路也可以,多多宜善,谢谢各位!!!
一定要实现动画的演示!!谢谢了!!!!!!

参考技术A 用什么啊?
C:
#include <stdio.h>
void hanoi(int n,char x,char y,char z);
void move(char x,int n,char y);
void main()

int num;
printf("Enter the number of disks:\\n");
scanf("%d",&num);
hanoi(num,\'a\',\'b\',\'c\');

void hanoi(int n,char x,char y,char z)

if(n==1)
move(x,1,z);
else
hanoi(n-1,x,z,y);
move(x,n,z);
hanoi(n-1,y,x,z);


void move(char x,int n,char y)

printf("%c->%d->%c\\n",x,n,y);

C++
#include <iostream>
using namespace std;
void hanoi(int,char,char,char);
void move(char,int,char);
int main()
int num;
cout<<"Enter the number of disks:";
cin>>num;
hanoi(num,'a','b','c');
return 0;

void hanoi(int n,char x,char y,char z)
if(n==1) move(x,1,z);
else
hanoi(n-1,x,z,y);
move(x,n,z);
hanoi(n-1,y,x,z);


void move(char x,int n,char y)
cout<<n<<" From "<<x<<" to "<<y<<endl

Pascal:
Program hanoi;
Var num;
procedure hanoi(n:integer;x,y,z:char);
begin
if n=1 then writeln("1 from x to z")
else begin
hanoi(n-1,x,z,y);
writeln(n,"from ",x," to ",z);
hanoi(n-1,y,x,z);
end;
end;
begin
readln(num);
hanoi(num,'x','y','z');
end.
参考技术B 493#include <stdio.h>
static void move(const char x,const int n,const char z)
printf("disc %d from %c to %c\n",n,x,z);

static void hanoi(const int n,const char x,const char y,const char z)
if(n==1)
move(x,1,z);
else
hanoi(n-1,x,z,y); //从这里开始就是关键
move(x,n,z);
hanoi(n-1,y,x,z); //到这里结束


int main()
int n;
printf("input a disc number:\n");
scanf("%d",&n);
hanoi(n,'x','y','z');
参考技术C #include <stdio.h>
long number;

void Move(char a,char b,int n)
char c=a=='a'?(b=='b'?'c':'b'):(a=='b'?(b=='a'?'c':'a'):(b=='a'?'b':'a'));
if(n==1)
number++,printf("NO.%8ld STEEP:move %c->%c\n",number,a,b);
else
Move(a,c,n-1);
Move(a,b,1);
Move(c,b,n-1);



main()
int n;
number=0;
do
printf("Please input the number of the box:");
scanf("%d",&n);

while(n<1&&printf("INPUT ERROR!\n")||n>40&&printf("TOO BIG NUMBER!\n"));
Move('a','c',n);
参考技术D 这是我们学校教材上的,绝对没有问题
#include <stdio.h>
main()

int n;
void movetower();
printf("Input the number of disks:");
scanf("%d",&n);
movetower(n,'A','B','C');

void movetower(n,a,b,c)
int n;
char a,b,c;

void movedisk();
if(n>0)
movetower(n-1,a,c,b);
movedisk(a,c);
movetower(n-1,b,a,c);


void movedisk(from,to)
char from,to;

printf("%c->%c\n",from,to);
第5个回答  2006-05-31 关于汉诺塔的程序设计,递归调用的使用巧妙。

main()

int n;
void movetower();
printf("Input the number of disks:");
scanf("%d",&n);
movetower(n,'A','B','C');

void movetower(n,a,b,c)
int n;
char a,b,c;

void movedisk();
if(n>0)
movetower(n-1,a,c,b);
movedisk(a,c);
movetower(n-1,b,a,c);


void movedisk(from,to)
char from,to;

printf("%c->%c\n",from,to);

找出一组数据中最大的数和最小的数,并将它们的位置互换。(C语言编程题,急求大神解答,明天早上要交...

找出一组数据中最大的数和最小的数,并将它们的位置互换。(C语言编程题,急求大神解答,明天早上要交,谢谢了)

参考技术A #include <stdio.h>

void main()

int dat[10]= 12, 34, 23, 45, 56, 21, 33, 39, 98, 76;
int max= dat[0], min= dat[0], i, maxnum= 0, minnum= 0;

for(i= 1; i < 10; i++)

if(dat[i] > max)

max= dat[i];
maxnum= i;


if(dat[i] < min)

min= dat[i];
minnum= i;



i= dat[maxnum];
dat[maxnum]= dat[minnum];
dat[minnum]= i;

for(i= 0; i < 10; i++)
printf("%d\n", dat[i]);
参考技术B 定义max,min两个变量,找出最大最小数的下标放入其中
将下标为max,min的两个数借助第三变量交换
也可以用指针做
参考技术C 不允许输入那么长啊,我学JAVA的,我用的是JAVA,前几天刚做过这道题。
你先创建一个数组然后再创建一个整型类型,初始值为数组中的第一个数,用循环来输出数组中每个数据,同时用判断语句来判断,然后排序输出
参考技术D 不知道 第5个回答  2012-11-22 不是什么大程序的话,用冒泡排序找

以上是关于急求一道编程题的主要内容,如果未能解决你的问题,请参考以下文章

一道c语言的题目 急求代码

急求一道c语言编程的答案!!时间急迫!!快快!!

C语言编程题,急求!!!!

请问这道c++编程题怎么做?(急求大神帮忙)——抽奖2

一道Java编程题

求一道python编程题