/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiTower(int n, char x, char y, char z){ if(n == 1){ std::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n'; }else{ hanoiTower(n-1,x,y,z); std::cout << "Disk " << n << " from " << x << " to " << z <<'\n'; hanoiTower(n-1,y,x,z); } }
int main(int argc, char** argv) { hanoiTower(5,'a','b','c'); return 0; }
/* run this program using the console pauser or add your own getch, system("pause") or input loop */ void hanoiTower(int n, char x, char y, char z){
if(n ==1){ std::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n'; }else{ hanoiTower(n-1, y, x, z); std::cout << "Disk " << n << " from " << x << " to " << z <<'\n'; hanoiTower(n-1, y, x, z); } }
29 則留言:
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiTower(int n, char x, char y, char z){
if(n == 1){
std::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
}else{
hanoiTower(n-1,x,y,z);
std::cout << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1,y,x,z);
}
}
int main(int argc, char** argv) {
hanoiTower(5,'a','b','c');
return 0;
}
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiTower(int n, char x, char y, char z){
if(n ==1){
std::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
}else{
hanoiTower(n-1, y, x, z);
std::cout << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
using namespace std;
void move(int n, char a, char b){
cout<<"Disc"<<n<<"從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1, from_peg, to_peg, peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1, peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
using namespace std;
void move(int n,char a,char b){
cout<<"disc"<<n<<"從"<<a<<"到"<<b<<endl;
}
void hanoitower(int n,char from_peg,char peg3,char to_peg)
{
if(n==1) move(n, from_peg , to_peg);
else{
hanoitower(n-1, from_peg , to_peg , peg3);
move(n, from_peg , to_peg );
hanoitower(n-1 , peg3, from_peg , to_peg);
}
}
int main()
{
hanoitower(5,'a','b','c');
return 0;
}
#include <iostream>
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiToewr(int n, char x, char y, char z) {
if ( n == 1) {
std::cout << "Disk "<< 1 << "form " << x << " to " << z <<'\n';
} else {
hanoiToewr(n-1, x, z, y);
std::cout << "Disk "<< 1 << "form " << x << " to " << z <<'\n';
hanoiToewr(n-1, x, z, y);
}
}
int main(int argc, char** argv) {
hanoiToewr(5, 'a','b','c');
return 0;
}
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std ::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std ::cout << "Disk " << 1 << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, x, z, y);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoitower(int n, char x, char y, char z ) {
if (n == 1) {
std::cout << "Disk " << 1 << " from " << x << " to "<< z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::cout << "Disk" << n << " from " << x << " to " << z<<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include <iostream>
void hanoitower(int n, char x, char y, char z ) {
if (n == 1) {
std::cout << "Disk " << 1 << " from " << x << " to "<< z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::cout << "Disk" << n << " from " << x << " to " << z<<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
using namespace std;
void move(int n, char a, char b){
cout<<"Disk "<<n<<" from "<<a<<" to "<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1, from_peg, to_peg, peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1, peg3, from_peg, to_peg);
}
}
int main() {
hanoiTower(5,'a','b','c');
return 0;
}
void hanoiTower(int n, cher x, cher y, cher z) {
if (n == 1){
std::count << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::count << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
void hanoiTower(int n, cher x, cher y, cher z) {
if (n == 1){
std::count << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::count << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
void hanoiTower(int n, cher x, cher y, cher z) {
if (n == 1){
std::count << "Disk " << 1 << " from " << x << " to " << z <<'\n';
} else {
hanoiTower(n-1, x, z, y);
std::count << "Disk " << n << " from " << x << " to " << z <<'\n';
hanoiTower(n-1, y, x, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}
#include
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}
#include
using namespace std;
void move (int n, char a, char b){
cout<<"Disc"<<n<<" 從"<<a<<"到"<<b<<endl;
}
void hanoiTower(int n, char from_peg, char peg3, char to_peg)
{
if(n==1) move(n, from_peg, to_peg);
else{
hanoiTower(n-1,from_peg, to_peg,peg3);
move(n, from_peg, to_peg);
hanoiTower(n-1,peg3, from_peg, to_peg);
}
}
int main()
{
hanoiTower(5, 'a','b','c');
return 0;
}
#include
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
#include
void hanoiTower(int n, char x, char y, char z);
void hanoiTower(int n, char x, char y, char z) {
if (n == 1) {
std::cout << "Disk" << 1 << "from" << x << "to" << z'\n';
} else {
hanoiTower(n-1, x, y, z);
std::cout << "Disk" << 1 << " from" << x << "to" << z'\n';
hanoiTower(n-1, x, y, z);
}
}
int main(int argc, char** argv) {
hanoiTower(5, 'a', 'b', 'c');
return 0;
}
張貼留言