Cod sursa(job #773724)

Utilizator 5t3fristea stefan 5t3f Data 2 august 2012 14:25:05
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
// permutari.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"
#include "fstream"
using namespace std;
ofstream g("permutari.out");
ifstream f("permutari.in");
int sol[9],fol[9],n,j;
void back(int x)
{
	int i;
	if(x==n+1)
	{
		for(j=1;j<=n;j++)
		{
			g<<sol[j]<<" ";
		}
		g<<"\n";
	}
	else
	{
		for(i=1;i<=n;i++)
			if(!fol[i])
			{
				sol[x]=i;
				fol[i]=1;
				back(x+1);
				fol[i]=0;
			}

	}
}
int main()
{
	f>>n;
	back(1);
	return 0;
}