Pagini recente » Cod sursa (job #3282872) | Cod sursa (job #319162) | Cod sursa (job #2497985) | Cod sursa (job #2212180) | Cod sursa (job #144403)
Cod sursa(job #144403)
#include <stdio.h>
int n,a[30100];
void afisare()
{
freopen ("order.in","r",stdin);
freopen ("order.out","w",stdout);
scanf ("%d",&n);
int aux,nr1,nr=1,ramase=n,poz=2;
while (nr<=n)
{
if (ramase<nr)
aux=(n%ramase+1);
else
aux=nr;
nr1=0;
int ok=0;
for (int i=poz;i<=n;i++)
if (a[i]==0)
{
nr1++;
if (nr1==aux)
{
ok=1;
a[i]=1;
poz=i;
printf ("%d ",i);
break;
}
}
if (ok==0)
{
for (int j=1;j<=n;j++)
{
if (a[j]==0)
{
nr1++;
if (nr1==aux)
{
a[j]=1;
poz=j;
printf ("%d ",j);
break;
}
}
}
}
ramase--;
nr++;
}
fclose(stdin);
fclose(stdout);
}
int main ()
{
afisare();
return 0;
}