Cod sursa(job #1637254)

Utilizator serbanSlincu Serban serban Data 7 martie 2016 16:02:36
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>
using namespace std;

int n;
bool v[10];
int x[10];

ofstream g("permutari.out");

void bkt(int i) {
    for(int j = 1; j <= n; j ++) {
        if(!v[j]) {
            x[i] = j; v[j] = true;
            if(i == n) {
                for(int o = 1; o <= n; o ++) g << x[o] << " ";
                g << "\n";
            }
            else bkt(i + 1);
            v[j] = false;
        }
    }
}

int main()
{
    ifstream f("permutari.in");
    f >> n;
    bkt(1);
    return 0;
}