Cod sursa(job #2884470)
Utilizator | dumnezEU hobbitczx | Data | 3 aprilie 2022 18:58:30 |
---|---|---|---|
Problema | Generare de permutari | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.73 kb |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin ("permutari.in");
ofstream fout ("permutari.out");
int n , x[105];
bool used[105];
void solve(){
for (int i=1; i<=n; i++){
fout << x[i] << " ";
}
fout << '\n';
}
void back (int k){
for (int i=1; i<=n; i++){
if (used[i] == false){
used[i] = true;
x[k] = i;
if (k <= n){
if (k == n){
solve();
}
else{
back(k + 1);
}
}
used[i] = false;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
fin >> n;
back(1);
}