⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 刘晖-6分.txt

📁 这是很不错的计算机算法
💻 TXT
字号:
#include <iostream.h>
#include <fstream.h>


void perm(int *out,int g,int h); //函数声明

ofstream fout("output.txt");

int main ()
{
int n,k,*a;
ifstream fin("input.txt",ios::nocreate,filebuf::sh_read);
fin>>n;
if(fin.fail())
{
cout<<"the input.txt is not exist!";
return 1;
}

if ((a=new int[n])==NULL) 
	{
	cout <<"内存不够,程序运行中止";
	return -1;
	}
for (k=0;k<n;k++) a[k]=k+1;

perm(a,0,n-1);
return 0;
}

void swap(int *a,int *b)
{
	int t;
	t=*a;
	*a=*b;
	*b=t;
}

void perm(int *out,int g,int h)
{
int i;
if (g==h) 
	{
	for(i=0;i<=h;i++) fout<<out[i];
	fout<<endl;
	}
else
	{
	for (i=g;i<=h;i++)
		{
		swap(out+g,out+i);
		perm(out,g+1,h);
		swap(out+g,out+i);
		}
	}
}

⌨️ 快捷键说明

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