Pagini recente » Cod sursa (job #3344319) | Cod sursa (job #1761345) | Cod sursa (job #2087216) | Cod sursa (job #206431) | Cod sursa (job #3304559)
#include <fstream>
using namespace std;
void permutari(int n, int pos, int* used, int* perm, ofstream& fout)
{
if (pos > n)
{
for (int i = 1; i <= n; ++i)
{
fout << perm[i] << " ";
}
fout << endl;
}
for (int i = 1; i <= n; ++i)
{
if (used[i])
continue;
perm[pos] = i;
used[i] = pos;
permutari(n, pos + 1, used, perm, fout);
used[i] = 0;
}
}
int main()
{
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n = 0;
fin >> n;
int* used = new int[n + 1];
int* perm = new int[n + 1];
for (int i = 0; i <= n; ++i)
used[i] = 0;
permutari(n, 1, used, perm, fout);
}