Cod sursa(job #1550709)
| Utilizator | Data | 14 decembrie 2015 16:16:01 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <iostream>
#include <fstream>
using namespace std;
int n;
int st[9];
ifstream fi("permutari.in");
ofstream fo("permutari.out");
bool check(int k)
{
for (int i = 1; i < k; i++)
if (st[i] == st[k])
return false;
return true;
}
void write()
{
for (int i = 1; i <= n; i++)
fo << st[i] << " ";
fo << "\n";
}
void perm(int k)
{
for (int i = 1; i <= n; i++)
{
st[k] = i;
if (check(k))
{
if (k == n)
write();
else
perm(k + 1);
}
}
}
int main()
{
fi >> n;
perm(1);
fi.close();
fo.close();
return 0;
}