Cod sursa(job #625031)
| Utilizator | Data | 23 octombrie 2011 17:11:05 | |
|---|---|---|---|
| Problema | Generare de permutari | Scor | 0 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include<stdio.h>
int x[100], n;
int bun(int k)
{
for(int j=1; j<k; j++)
if(x[j]==x[k])
return 0;
return 1;
}
void back(int i)
{
while(i>0&& i<=n)
{
x[i]++;
if(x[i]>n)
{
x[i]=0;
i--;
}
else
if(bun(i))
i++;
if(i>n)
{
for(int j=1;j<=n;j++)
printf("%d ", x[j]);
printf("\n");
i=n;
}
}
}
int main()
{
freopen("permutari.in", "r", stdin);
freopen("permutari.out", "w", stdout);
scanf("%d", &n);
back ( 1 );
return 0;
}