Cod sursa(job #358203)

Utilizator auRSTARHreapca Aurelian auRSTAR Data 22 octombrie 2009 09:59:35
Problema Generare de permutari Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
void read(),solve();
int n,i,x[10],j,f=1;
int main()
{
	read();
	solve();
	return 0;
}
void read()
{
	freopen("permutari.in","r",stdin);
	freopen("permutari.out","w",stdout);
	scanf("%d", &n);
}
void solve()
{
	for(i=1;i<=n;i++)
	{
		f*=i;
		x[i]=i;
	}
	for(i=1;i<=f;i++)
	{
		for(j=1;j<=n;j++)
			printf("%d ",x[i]);
		printf("\n");
		next_permutation(x+1,x+n+1);
	}
}