Cod sursa(job #144403)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 27 februarie 2008 16:13:14
Problema Order Scor 65
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#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;
}