Pagini recente » Cod sursa (job #3365504) | Profil koppa5964 | Cod sursa (job #3365655) | Statistici Mihnea Andreescu (NewGlory) | Cod sursa (job #3365803)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n, p[10], used[10];
void back(int poz)
{
if (poz == n + 1)
{
for (int i = 1; i <= n; i++)
fout << p[i] << " ";
fout << '\n';
return;
}
for (int val = 1; val <= n; val++)
{
bool folosit = false;
if (!used[val])
folosit = true;
if (folosit)
{
p[poz] = val;
used[val] = 1;
back(poz + 1);
used[val] = 0;
}
}
}
int main()
{
fin >> n;
back(1);
}