Pagini recente » Cod sursa (job #970789) | Cod sursa (job #2881349) | Cod sursa (job #2080338) | Cod sursa (job #2050214) | Cod sursa (job #1971462)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
const int Nmax=9;
int N,V[Nmax],j,Use[Nmax];
bool Ok(int i)
{
if(Use[V[i]]==0)
{
Use[V[i]]=1;
return 1;
}
else return 0;
}
void Print()
{
for(int i=1;i<=N;++i)
{
fout<<V[i]<<" ";
}
fout<<"\n";
}
void Back(int i)
{
for(int j=1;j<=N;++j)
{
V[i]=j;
if(Ok(i))
{
if(i==N)
{
Print();
}
Back(i+1);
Use[j]=0;
}
}
}
int main()
{
fin>>N;
Back(1);
return 0;
}