Cod sursa(job #552051)
| Utilizator | Data | 11 martie 2011 16:14:16 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include<fstream.h>
int st[9],n;
ofstream g("permutari.out");
void tipar(int p)
{ int j;
for(j=1;j<=p;j++)
g<<st[j]<<' ';
g<<'\n';
}
bool valid (int p)
{
int i;
bool ok;
ok=1;
for(i=1;i<=p-1;i++)
if(st[p]==st[i])
ok=0;
return ok;
}
void back(int p)
{
int pval;
for(pval=1;pval<=n;pval++)
{
st[p]=pval;
if(valid(p))
if(p==n) tipar(p);
else back(p+1);
}
}
int main()
{
ifstream f("permutari.in");
f>>n;
back(1);
}