Pagini recente » Cod sursa (job #2347089) | Utilizatori inregistrati la Winter Challenge 2008, runda 1 | Cod sursa (job #1876475) | Cod sursa (job #566472) | Cod sursa (job #1813638)
#include <bits/stdc++.h>
using namespace std;
int n, top, st[81];
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int Valid()
{
int i;
for(i=1; i<top; i++)
if(st[i]==st[top])
return 0;
return 1;
}
void Afisare()
{
for(int i=1; i <= n; i++)
fout<<st[i]<<" ";
fout<<"\n";
}
void Back()
{
int cand;
st[++top]=0;
while(top)
{
cand=0;
while(!cand && st[top] < n)
{
st[top]++;
cand=Valid();
}
if(cand==0) top--;
else if(top==n) Afisare();
else st[++top]=0;
}
}
int main()
{
fin>>n;
Back();
return 0;
}