Cod sursa(job #1680763)

Utilizator matei140401Iorgulescu Matei matei140401 Data 9 aprilie 2016 08:13:07
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <fstream>
using namespace std;
int a[19],b[19];
ifstream fin("permutari.in");
ofstream fout("permutari.out");

void back(int k,int c)
{
    int i;
    if(k-1 == c)
    {
        for( i = 1; i <= c; i++)
            fout<<a[i]<<" ";
        fout<<"\n";
    }
    else
    {
        for(int  i = 1; i <= c; i++)
            if(!b[i])
            {
                a[k] = i;
                b[i] = 1;
                back(k+1,c);
                b[i] = 0;
            }
    }
}

int main()
{

    int n;
    fin>>n;
    back(1,n);

    return 0;
}