Jump to content
HiDinjection

[Help C++] Turnurile din Hanoi

Recommended Posts

Salut,

Ma poate ajuta si pe mine cu aceasta problema facuta in C++?

Problema Turnurilor din Hanoi este cunoscuta de toata lumea nu cred ca are sens sa o explic. Trebuie sa realizez algoritmul pentru un numar "n" de disk'uri citit de la tastatura. Iar dupa fiecare etapa sa apara pe ecran stagiul in care se afla. Gen o simulare. Sa arate dupa fiecare etapa ceva in genul:

4

5 1

6 2 3

Link to comment
Share on other sites

google.

Incearca pe info.mcip.ro ( nu cred ca are search site-ul , incearca toate categoriile, probabil gasesti la clasa a 11-a.)

Scuze daca nu e ceva concret, asta e tot ce mi-a venit in cateva secunde dupa ce ti-am citit titlu.

Am gasit-o, tot pe google :P

Imgur

Edited by seboo00111
meh
Link to comment
Share on other sites

Uite si in C++

#include<iostream>

using namespace std;

char a,b,c;

int n;

void Hanoi(int n,char a,char b, char c)

{

if(n==1)

cout<<a<<"->"<<b<<endl;

else

{

Hanoi(n-1,a,c,B);

cout<<a<<"->"<<b<<endl;

Hanoi(n-1,c,b,a);

}

}

int main()

{

cout<<"n=";cin>>n;

Hanoi(n,'A','B','C');

return 1;

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...