Pagini recente » Cod sursa (job #1369685) | Cod sursa (job #1918106) | Cod sursa (job #1152428) | Cod sursa (job #339833) | Cod sursa (job #1247408)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n,st[20];
void Afisare(int top)
{
int i;
for(i=1;i<=top;i++)
fout<<st[i]<<" ";
fout<<"\n";
}
int Valid(int top,int x)
{
int i;
for(i=1;i<top;i++)
if(st[i]==x)
return 0;
return 1;
}
void Back(int top)
{
int i;
if(top==n+1) Afisare(top-1);
else for(i=1;i<=n;i++)
if(Valid(top,i))
{
st[top]=i;
Back(top+1);
}
}
int main()
{
fin>>n;
Back(1);
return 0;
}