Cod sursa(job #144392)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 27 februarie 2008 16:01:11
Problema Order Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 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=1;
   while (nr<=n)
   {
      if (ramase<nr)
	 aux=nr%ramase;
      else
	aux=nr;

     nr1=0;
     int ok=0;
     for (int i=poz;i<=n;i++)
       if (a[i]==0)
       {
	  if (nr1==aux)
	  {
	     ok=1;
	     a[i]=1;
	     poz=i;
	     printf ("%d ",i);
	     break;
	  }
	  else
	     nr1++;
       }

     if (ok==0)
     {
     for (int j=1;j<=n;j++)
     {
       if (a[j]==0)
       {
	  if (nr1==aux)
	  {
	     a[j]=1;
	     poz=j;
	     printf ("%d ",j);
	     break;
	  }
	  else
	    nr1++;
       }
     }
     }
     ramase--;
     nr++;
   }


   fclose(stdin);
   fclose(stdout);

}

int main ()
{
   afisare();
   return 0;
}