Pagini recente » Cod sursa (job #915749) | Cod sursa (job #2109328) | Statistici Sandu George (GeorgeSandu2001111) | Cod sursa (job #950891) | Cod sursa (job #2212598)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("permutari.in");
ofstream g("permutari.out");
int n,st[100];
int cond(int k)
{
for(int i=1;i<=k-1;i++)
if(st[k]==st[i])return 0;
return 1;
}
void afisare(int k)
{
for(int i=1;i<=k;i++)
g<<st[i]<<" ";
g<<"\n";
}
void bt()
{
int k=1;
st[k]=0;
while(k>0)
{
st[k]++;
if(st[k]<=n)
{
if(cond(k))if(k==n)afisare(k);
else
{
k++;
st[k]=0;
}
}
else k--;
}
}
int main()
{
f>>n;
bt();
}