Pagini recente » Istoria paginii runda/5_martie_simulare_oji_2024_clasa_10 | Cod sursa (job #470041) | Cod sursa (job #2379141) | Cod sursa (job #1632553) | Cod sursa (job #2829236)
#include <fstream>
using namespace std;
ifstream fin("grader_test2.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;
}