Cod sursa(job #604840)
Utilizator | Data | 25 iulie 2011 16:53:48 | |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 1.11 kb |
#include<fstream>
using namespace std;
int st[20],k,n;
bool as,ev;
int main(void){
ifstream fin("permutari.in");
ofstream fout("permutari.out");
fin>>n; fin.close();
k=1;
st[k]=0;
while(k){
do{
if(st[k]<n)
{
st[k]+=1;
as=true;
}
else as=false;
if (as){
ev=true;
for(int i=1;i<k;++i) if(st[i]==st[k])ev=false;
}
}while(!( !as or as&&ev));
if (as)
if (k==n) { for(int i=1;i<=k;++i) fout<<st[i]<<" "; fout<<"\n"; }
else
{
++k;
st[k]=0;
}
else
k=k-1;
}
fout.close();
return 0;
}