Pagini recente » Cod sursa (job #2144965) | Cod sursa (job #116702) | Cod sursa (job #998115) | Cod sursa (job #304309) | Cod sursa (job #990484)
Cod sursa(job #990484)
#include <cstdio>
using namespace std;
int n,st[10];
inline bool Valid(int top)
{
int i;
for(i=1;i<top;i++)
if(st[top]==st[i])
return false;
return true;
}
inline void Afisare()
{
int i;
for(i=1;i<=n;i++)
printf("%d ", st[i]);
printf("\n");
}
int main()
{
bool cand;
int top;
freopen ("permutari.in","r",stdin);
freopen ("permutari.out","w",stdout);
scanf("%d", &n);
top=1;st[1]=0;
while(top>0)
{
cand=false;
while(!cand && st[top]<n)
{
st[top]++;
cand=Valid(top);
}
if(!cand)
top--;
else
if(top==n)
Afisare();
else
st[++top]=0;
}
return 0;
}