Cod sursa(job #2924757)
Utilizator | Fabian Lucian Redstoneboss2 | Data | 10 octombrie 2022 08:21:35 |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.65 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari.in");
ofstream fout("permutari.out");
int n, per[10];
bool vf[10];
void BACK(int depth);
int main()
{
fin >> n;
BACK(1);
return 0;
}
void BACK(int depth){
for(int i = 1; i <= n; i++){
if(vf[i] == 0){
per[depth] = i;
vf[i] = 1;
if(depth == n){
for(int j = 1; j <= n; j++){
fout << per[j] << ' ';
}
fout << '\n';
}else{
BACK(depth+1);
}
vf[i] = 0;
}
}
}