Pagini recente » bruh | Cod sursa (job #1874610) | Atasamentele paginii Profil D_Dan | Cod sursa (job #2711176) | Cod sursa (job #1275516)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int x[9],n;
int cont(int k)
{
for (int i=1;i<k;i++)
if(x[k]==x[i])
return 0;
return 1;
}
void tipar(int k)
{
for(int i=1;i<=k;i++)
fout<<x[i]<<" ";
fout<<'\n';
}
void back()
{
int k=1;
x[k]=0;
while (k>0)
if(x[k]<n)
{
x[k]=x[k]+1;
if (cont(k))
{
if(k==n)
tipar(k);
else
{
k++;
x[k]=0;
}
}
}
else k--;
}
int main()
{
fin>>n;
back();
return 0;
}