Pagini recente » Statistici Arbi Elei (arbii123) | Statistici Andrei (andrei_sebi15) | nambartiori | Cod sursa (job #2667739)
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n, k, x[10];
bool ok(int k)
{
for(int i = 1; i < k; i++)
if(x[k] == x[i])
return 0;
return 1;
}
void BK(int k)
{
for(int i = 1; i <= n; i++)
{
x[k] = i;
if(ok(k))
{
if(k == n)
{
for(int i = 1; i <= k; i++)
fout << x[i] <<' ';
fout<<'\n';
}
else
BK(k+1);
}
}
}
int main()
{
fin >> n;
BK(1);
return 0;
}