?? main.cpp
字號:
#include<iostream.h>
void move2(int count, int start, int finish, int temp);
void move(int count, int start, int finish, int temp)
{
if (count > 0) {
move2(count - 1, start, temp, finish);
cout << "Move disk " << count << " from " << start
<< " to " << finish << "." << endl;
move2(count - 1, temp, finish, start);
}
}
void move2(int count, int start, int finish, int temp)
{
int swap;
while (count > 0) {
move(count - 1, start, temp, finish);
cout << "Move disk " << count << " from " << start
<< " to " << finish << "." << endl;
count--;
swap = start;
start = temp;
temp = swap;
}
}
void main()
{
int n;
bool flag=true;
char ch;
cout<<"Please input number of disks ( > 0 ) to move:"<<endl;
cin>>n;
cin.get();
while(flag && n>0)
{
move2(n, 1, 3, 2);
cout<<"Continue(y/n)?"<<endl;
ch=cin.get();
if (ch=='y')
{
cout<<"Please input number of disks ( > 0 ) to move:"<<endl;
cin>>n;
cin.get();
}
else
flag=false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -