Cod sursa(job #1173430)

Utilizator EhtRalpmetFMI Ardei Claudiu-Alexandru EhtRalpmet Data 19 aprilie 2014 18:10:15
Problema Generare de permutari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
//#include<iostream>
#include<fstream>
#include<vector>

using namespace std;
ifstream cin("permutari.in");
ofstream cout("permutari.out");

int n;
bool bl[10];
vector<char> c;

void perm(int x){
    bl[x]=1;
    if(c.size()==n){
        for(int j=0;j<c.size();j++){
            cout<<c[j]<<' ';
        }
        cout<<'\n';
    }
    for(int i=1;i<=n;i++){
        if(!bl[i]){
            c.push_back('0'+i);
            perm(i);
        }
    }
    bl[x]=0;
    c.pop_back();
}

int main() {
    cin>>n;
    for(int i=1;i<=n;i++){
        c.push_back('0'+i);
        perm(i);
    }

    return 0;
}