Chinaunix首页 | 论坛 | 博客
  • 博客访问: 222752
  • 博文数量: 48
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 412
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-24 10:27
个人简介

Continuous pursuit technical details

文章分类

全部博文(48)

文章存档

2014年(1)

2013年(47)

分类: C/C++

2013-11-28 09:16:48

/*
 * hanoti.cpp
 *
 *  Created on: 2013-8-17
 *      Author: erzhou
 */




#include
#include
#include


using namespace std;


char A,B,C;
int times = 0;


int main()
{
    int n;
    void hanoi(int,char,char,char);
    cout << "Please Input number of blades" << endl;
    cin>>n;
    cout << "Number is " << n << endl;
    cout << "new Starting ....... " << endl;
    cout << "=======================================" << endl;
    hanoi(n,'A','B','C');
    cout << "Finished, cost " << times << " times" << endl;
    cout << "=======================================" << endl;
    return 0;
}


void display(char A, char C){
times ++;
cout << times << " " << A << " ==> " << C << endl;
}


void hanoi(int n, char A, char B, char C){
if (n==1){
display(A,C);
}else{
hanoi(n-1,A,C,B);
display(A,C);
hanoi(n-1,B,A,C);
}
}


阅读(1318) | 评论(0) | 转发(0) |
0

上一篇:gprof

下一篇:使用openssl api进行加密解密

给主人留下些什么吧!~~