Pagini recente » Cod sursa (job #463012) | Cod sursa (job #487143) | Cod sursa (job #463032) | Cod sursa (job #2900960)
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n, sol[10];
bool used[10];
void bkt(int k)
{
for(int i = 1; i <= n; i++)
{
if(used[i])
continue;
sol[k] = i;
used[i] = 1;
if(k == n)
{
for(int j = 1; j <= n; j++)
fout << sol[j] << ' ';
fout << '\n';
}
else
bkt(k + 1);
used[i] = 0;
}
}
int main()
{
fin >> n;
bkt(1);
return 0;
}