Cod sursa(job #847863)
Utilizator | Data | 4 ianuarie 2013 16:28:39 | |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
bool use[20];
int v[20];
void f(int n, int i)
{
int j;
if(i<=n)
{
for(j=1;j<=n;j++)
{
if(use[j]==0)
{
use[j]=true;
v[i]=j;
f(n,i+1);
use[j]=false;
}
}
}
else
{
for(j=1;j<=n;j++)
fout<<v[j]<<" ";
fout<<"\n";
}
}
int main ()
{
int n;
fin>>n;
f(n,1);
}