Pagini recente » Cod sursa (job #2464946) | Cod sursa (job #2968571) | Cod sursa (job #2095678) | Cod sursa (job #2472571) | Cod sursa (job #1696392)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n,st[10];
int Valid(int top)
{
int i;
for(i=1;i<top;i++)
if(st[i]==st[top]) return 0;
return 1;
}
void Afisare(int top)
{
int i;
for(i=1;i<=top;i++)
fout<<st[i]<<" ";
fout<<"\n";
}
void Back()
{
int top,cand;
top=1;
st[top]=0;
while(top>0)
{
cand=0;
while(!cand &&st[top]<n)
{
st[top]++;
cand=Valid(top);
}
if(!cand) top--;
else if(top==n) Afisare(top);
else {
top++;
st[top]=0;
}
}
}
int main()
{
fin>>n;
Back();
return 0;
}