王敏-6分.txt

来自「这是很不错的计算机算法」· 文本 代码 · 共 27 行

TXT
27
字号
#include<fstream.h>

void move(int n,char a,char b,ofstream& out1)
{
   
	out1<<n<<' '<<a<<' '<<b<<'\n';
}

void hanoi(int n,char a,char b,char c,ofstream& out1)
{
	if (n>0)
	{
		hanoi(n-1,a,c,b,out1);
		move(n,a,b,out1);
		hanoi(n-1,c,b,a,out1);
	}
}

void main()
{
	int n;
	char A='A',B='B',C='C';
   ifstream fin("input.txt");
    fin>>n;
   ofstream out1("output.txt");
   hanoi(n,A,B,C,out1);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?