Cod sursa(job #2288985)

Utilizator stefzamfirStefan Zamfir stefzamfir Data 24 noiembrie 2018 10:04:57
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 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()

{
    freopen("permutari.in","r",stdin);
    freopen("permutari.out","w",stdout);
    ios_base::sync_with_stdio(false);

    cin >> n;

    Back(1);

    return 0 ;

}