Cod sursa(job #3213673)

Utilizator tomaionutIDorando tomaionut Data 13 martie 2024 12:43:21
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, top, v[10], st[10];

void Afisare()
{
    for (int i = 1; i <= n; i++)
        fout << st[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;
                st[top] = i;
                Back(top + 1);
                v[i] = 0;
            }
}

int main()
{
    fin >> n;
    Back(1);

    return 0;
}