Cod sursa(job #2364731)

Utilizator RazvanCostinRazvan Costin RazvanCostin Data 4 martie 2019 10:40:39
Problema Generare de permutari Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>

using namespace std;
int st[100],n;
void afisare(int p)
{
    for(int i=1;i<=p;i++)
        cout<<st[i]<<" ";
    cout<<endl;
}

bool valid(int p)
{
    for(int i=1;i<p;++i)
        if(st[i]==st[p])
            return false;
    return true;
}

void back(int p)
{
    int pval;
    for(pval=1;pval<=n;pval++)
    {
        st[p]=pval;
        if(valid(p))
            if(p==n)
                afisare(p);
        else
            back(p+1);
    }
}

int main()
{
    cin>>n;
    afisare(p);
    return 0;
}