Cod sursa(job #2479344)

Utilizator iustin948Homoranu Iustin iustin948 Data 23 octombrie 2019 18:25:58
Problema Generare de permutari Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int st[10], v[10], n;

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

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

int main()
{
    fin >> n;
    Back(1);
    return 0;
}