Cod sursa(job #1583858)

Utilizator gorni97aaa aaa gorni97 Data 29 ianuarie 2016 14:20:09
Problema Generare de permutari Scor 80
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
using namespace std;
fstream g("permutari.out",ios::out);
int x[20],k,as,ev,n;

void init()
{x[k]=0;}

void succesor()
{
    if(x[k]<n)
    {x[k]++;as=1;
    }else as=0;
}

void valid()
{ev=1;int i;
for(i=1;i<k;i++)
    if(x[i]==x[k])
    ev=0;
}

int solutie()
{return (k==n);}

void tipar()
{int i;


    for(i=1;i<=k;i++)
       {

        g<<x[i]<<" ";

    }g<<endl;

}

int main()



{ fstream f("permutari.in",ios::in);

f>>n;

k=1;
init();


while(k>0)
{do{succesor();
if(as)
    valid();
}while((as)&&((!as)||(!ev)));
if(as)
    if(solutie())
    tipar();
else
{k++;init();}
else
    k--;
}

g.close();

}