Pagini recente » Cod sursa (job #437086) | Cod sursa (job #775808) | Cod sursa (job #626101) | Cod sursa (job #2195482) | Cod sursa (job #1655499)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("permutari.in");
ofstream out("permutari.out");
int n;
const int NMAX = 9;
typedef int stiva[NMAX];
stiva st;
int vf = 1;
int ok()
{
for(int i=1;i<vf;i++)
if(st[i]==st[vf])
return 0;
return 1;
}
void afisare()
{
for(int i=1;i<=vf;i++)
out<<st[i]<<" ";
out<<"\n";
}
int main()
{
in>>n;
in.close();
st[vf] = 0;
while(vf)
{
st[vf]++;
if(st[vf] > n)
vf--;
else
{
if(ok())
{
if(vf==n)
afisare();
else
st[++vf] = 0;
}
}
}
out.close();
return 0;
}