Cod sursa(job #873548)
| Utilizator | Data | 7 februarie 2013 13:04:44 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
int i,gas[9],n,val[9];
ofstream f2("permutari.out");
void rez(int poz,int n)
{
if (poz<=n)
for (int y=1;y<=n;++y)
{
if (!gas[y])
{
gas[y]=1;
val[poz]=y;
rez(poz+1,n);
gas[y]=0;
}
}
else
{
for (int o=1;o<=n;++o)
f2<<val[o]<<' ';
f2<<'\n';
}
}
int main()
{
ifstream f1("permutari.in");
f1>>n;
rez(1,n);
return 0;
}
