Cod sursa(job #2366153)

Utilizator _Tudor_Tudor C _Tudor_ Data 4 martie 2019 18:45:25
Problema Generare de permutari Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");

void printArr(int arr[], int n)
{
    for(int i = 0; i < n; ++i)
        fout << arr[i] << ' ';
    fout << '\n';
}

void permutations(int str[], int i, int n)
{
    if(i == n - 1)
    {
        printArr(str, n);
        return;
    }
    for(int j = i; j < n; j++)
    {
        swap(str[i], str[j]);

        permutations(str, i + 1, n);

        swap(str[i], str[j]);
    }
}

int main()
{
    int a[10];
    int n;
    fin >> n;

    for(int i = 0; i < n; ++i)
        a[i] = i + 1;

    permutations(a, 0, n);
}