Cod sursa(job #730895)
| Utilizator | Data | 7 aprilie 2012 00:31:50 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.67 kb |
#include <stdio.h>
using namespace std;
const int MAX = 10;
bool ap[MAX]; int v[MAX], n;
void back(int poz)
{
for(int i = 1; i <= n; i++)
{
if(!ap[i])
{
ap[i] = true; v[poz] = i;
if(poz == n)
{
for(int j = 1; j <= n; j++)
printf("%d ", v[j]);
printf("\n");
}
else
back(poz + 1);
ap[i] = false;
}
}
}
int main()
{
freopen("permutari.in", "r", stdin);
freopen("permutari.out", "w", stdout);
scanf("%d", &n);
back(1);
fclose(stdin);
fclose(stdout);
}
