Pagini recente » template/autor-necunoscut | Cod sursa (job #2361472) | Cod sursa (job #2005667) | Cod sursa (job #348066) | Cod sursa (job #2170800)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n,st[15],fv[15];
void init(int nivel)
{
st[nivel]=0;
}
bool rezultat(int nivel)
{
if(nivel==n)
return 1;
else
return 0;
}
bool validare(int nivel)
{
if(fv[st[nivel]]==0)
return 1;
else
return 0;
}
bool exista(int nivel)
{
if(st[nivel]<n&&nivel<=n)
return 1;
else
return 0;
}
void bk()
{
int nivel,i;
nivel=1;
while(nivel>0)
{
if(exista(nivel))
{
st[nivel]++;
if(validare(nivel))
{
if(rezultat(nivel))
{
for(i=1; i<=n; i++)
fout<<st[i]<<' ';
fout<<'\n';
}
else
{
fv[st[nivel]]=1;
nivel++;
init(nivel);
}
}
}
else
{
nivel--;
fv[st[nivel]]=0;
}
}
}
int main()
{
fin>>n;
bk();
}