Cod sursa(job #2564932)

Utilizator NotTheBatmanBruce Wayne NotTheBatman Data 2 martie 2020 11:08:59
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
#include <bitset>

using namespace std;

const int N = 10;

int n, st[N], f[N];

ofstream fout ("permutari.out");

void Write (int x)
{
    for (int i = 1; i <= x; i++)
        fout << st[i] << " ";
    fout << "\n";
}

void Back (int top)
{
    if (top > n)
        Write(top - 1);
    else for (int i = 1; i <= n; i++)
        if (!f[i])
        {
            f[i] = 1;
            st[top] = i;
            Back(top + 1);
            f[i] = 0;
        }
}

void Read ()
{
    ifstream fin ("permutari.in");
    fin >> n;
    Back(1);
}


int main()
{
    Read();
    return 0;
}