Cod sursa(job #2449513)
| Utilizator | Data | 19 august 2019 22:58:15 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.52 kb |
#include <cstdio>
using namespace std;
int n;
bool free[8];
int solu[8];
void LQ(int S) {
if (S == n) {
for (int j = 0; j < n; j++)
printf("%d ", solu[j] + 1);
printf("\n");
} else {
for (int j = 0; j < n; j++)
if (!free[j]) {
free[j] = 1;
solu[S] = j;
LQ(S + 1);
free[j] = 0;
}
}
}
int main() {
freopen ("permutari.in", "r", stdin);
freopen ("permutari.out", "w", stdout);
scanf("%d", &n);
LQ(0);
return 0;
}
