Cod sursa(job #2865566)

Utilizator tomaionutIDorando tomaionut Data 8 martie 2022 22:18:33
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n, s[25], v[25];
void Afisare()
{
    int i;
    for (i = 1; i <= n; i++)
        fout << s[i] << " ";
    fout << "\n";
}
void Back(int top)
{
    if (top == n + 1)
        Afisare();
    else
    {
        for (int i = 1; i <= n; i++)
            if (v[i] == 0)
            {
                v[i] = 1;
                s[top] = i;
                Back(top + 1);
                v[i] = 0;
            }
    }
}
int main()
{
    fin >> n;
    Back(1);


    return 0;
}