梁淘-5分.txt

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

TXT
48
字号
#include <iostream.h>
#include <math.h>
#include <fstream.h>

int q(int,int);
	
void main(void)
{

/*从文件中读出数据*/
	int nn;
	ifstream  fopen("input.txt");
	if (! fopen)
	{
		cout<<"Cannot open the file"<<'\n';
		return ;
	}
	fopen>>nn;
	fopen.close();

/*调用递归函数*/
	int pn;
	pn=q(nn,nn);

/*数据写入文件*/
	ofstream outf("output.txt");
	if (! outf)
	{
		cout<<"Cannot open the file"<<'\n';
		return ;
	}
    outf<<pn<<'\n';
	outf.close();
	return ;

}

/*计算正整数n的划分数的递归函数*/
int q(int n,int m)
{
	if ((n<1)||(m<1)) return 0;
	if ((n==1)||(m==1)) return 1;
	if (n<m) return q(n,n);
	if (n==m) return q(n,m-1)+1;
	return q(n,m-1)+q(n-m,m);
}

⌨️ 快捷键说明

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