Pagini recente » Cod sursa (job #2109444) | Cod sursa (job #496870) | Cod sursa (job #2703595) | Cod sursa (job #2173971) | Cod sursa (job #2829238)
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
void f(int nivel, int k, int sol[])
{
if (nivel == k+1)
{
for (int i = 1; i <= k; i++)
fout << sol[i] << ' ';
fout << endl;
}
else
for (int i = 1; i <= k; i++)
{
bool ok = 1;
int j = 1;
while(j < nivel && ok)
if(sol[j] == i)
ok = 0;
else
j++;
if(ok)
{
sol[nivel] = i;
f(nivel+1, k, sol);
}
}
}
int main()
{
int k;
fin >> k;
int sol[k+1];
f(1, k, sol);
return 0;
}