Cod sursa(job #2288983)

Utilizator stefzamfirStefan Zamfir stefzamfir Data 24 noiembrie 2018 10:04:17
Problema Generare de permutari Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include<iostream>

using namespace std;

int a[20], n, viz[20];

void PrintSol()

{

    int i;

    for (i = 1; i <= n; i++)

        cout << a[i] << " ";

    cout << "\n";

}

void Back(int top)

{

    int i;

    if (top == n + 1) PrintSol();

    else for (i = 1; i <=n; i++)

            if (!viz[i])

            {

                viz[i] = 1;

                a[top] = i;

                Back(top + 1);

                viz[i] = 0;

            }

}

int main()

{
    ios_base::sync_with_stdio(false);
    cout << "n = ";

    cin >> n;

    Back(1);

    return 0 ;

}