Cod sursa(job #2192904)

Utilizator gabiluciuLuciu Gabriel gabiluciu Data 7 aprilie 2018 17:20:56
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
using namespace std;
ifstream in("permutari.in");
ofstream out("permutari.out");
int a[10],n,v[10];
void print(){
    for(int i=1;i<=n;++i)
        out<< a[i] << ' ';
    out<< '\n';
}
void Back(int top){
    if(top==n+1)print();
    else for(int i = 1;i<=n;++i)
        if(!v[i]){
            v[i]=1;
            a[top] = i;
            Back(top+1);
            v[i] = 0;
        }
}
int main()
{
    in>>n;
    Back(1);
    return 0;
}