Cod sursa(job #2437625)
| Utilizator | Data | 9 iulie 2019 21:32:59 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.62 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("permutari.in");
ofstream fout ("permutari.out");
int a[9], n;
bool check(int n)
{
for(int i = 1; i < n; ++i) if(a[i] == a[n]) return 0;
return 1;
}
int solve(int k)
{
for(int i = 1; i <= n; ++i) {
a[k] = i;
if(check(k)) {
if(k != n) solve(k + 1);
else {
for(int j = 1; j <= n; ++j) fout << a[j] << " ";
fout << "\n";
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
fin >> n;
solve(1);
return 0;
}
