int hanoi(int **p, int n, int A, int B, int C)
    {
          if (n == 0 )
              return 0;

          hanoi(p, n-1,A,C, B);

          traiter(p, A, C, N);

          hanoi(p, n-1,B, A, C);
          return 1;
    }
Example #2
0
char *droits(struct stat *pstat)
{
    mode_t mode;
    char* modes = malloc(sizeof(10));
    int indice_mode = 0;

    mode = pstat->st_mode;

    traiter(mode & S_IRUSR, 'r', '-', &indice_mode, modes);
    traiter(mode & S_IWUSR, 'w', '-', &indice_mode, modes);
    traiter(mode & S_IXUSR, 'x', '-', &indice_mode, modes);
    traiter(mode & S_IRGRP, 'r', '-', &indice_mode, modes);
    traiter(mode & S_IWGRP, 'w', '-', &indice_mode, modes);
    traiter(mode & S_IXGRP, 'x', '-', &indice_mode, modes);
    traiter(mode & S_IROTH, 'r', '-', &indice_mode, modes);
    traiter(mode & S_IWOTH, 'w', '-', &indice_mode, modes);
    traiter(mode & S_IXOTH, 'x', '-', &indice_mode, modes);
    modes[indice_mode] = '\0';
    return modes;
}
Example #3
0
long bourse (int argc, char *argv[],
        int alpha, int beta, int alpha1, int beta1,
        int c0, int d0, int c1, int d1)
{
FILE *f;
/* char line[1000]; */
struct s_line line;
struct s_record record;
char buf[1000];
int code;
struct s_record records[MAX];
int i, j, p;
long x;

        alpha_0 = alpha;
        beta_0 = beta;
        alpha_1 = alpha1;
        beta_1 = beta1;
        gamma_0 = c0;
        delta_0 = d0;
        gamma_1 = c1;
        delta_1 = d1;

        f = fopen (argv[1], "r");
        if (f == NULL)
        {
                perror ("fopen");
                return;
        }
        code = 0;
        mdl = 0;
        minv = INF;
	p = 10;
	i = 0;
        for (;;)
        {
                /* fgets (&line, sizeof(line), f); */
                /* get_line (f, &line); */
                get_record (f, &record);
                /* printf ("%s\n", record.nom); */
                if (feof(f))
                        break;
                /* print_line (&line); */
                /* print_record (&record); */
                /* gets (buf); */
                if (record.code != code)
                {
                        if (code)
                        {
                                records[i].status = 0;
                                /* if (i >= 10)
                                        traiter (records, n);
                                else
                                        traiter (records, i); */
                                traiter (records, i, p);
                        }
                        code = record.code;
                        i = 0;
                }
                memcpy (records+i, &record, sizeof(struct s_record));
                i++;

        }
        for (j=0; mrecords[j].status; j++);
        j = nm;
        /* printf ("benefice : %ld%%\n", (long) ((mrecords[j-1].l - mrecords[p-1].l) * 100 / mrecords[p-1].l - 100)); */
        /* printf ("%d %ld  %d %ld\n",
                p, mrecords[p-1].l, j, mrecords[j-1].l); */
        x = ((mrecords[j-1].l - mrecords[p-1].l) * 100 / mrecords[p-1].l );
        /* printf ("%d %d\n", x, x>>16); */
        fclose (f);
        return x;

}
Example #4
0
int main(int argc,char *argv[])
{
  int fc;
  int totalc=0;
  int totalw=0;
  int totall=0;
  int i=1;
  int j=0;
  int plusieurfichier=0;
  int opC=0;
  int opW=0;
  int opL=0;
  int car=0;
  int mots=0;
  int lignes=0;

  while(i<argc && argv[i][0]=='-') {
    j=1;
    if (argv[i][1] == '\0') {
      printf("Erreur d'argument: '%s'\n", argv[i]);
      exit(1);
    }

    while(argv[i][j]!='\0') {
      if(argv[i][j] != 'l' && argv[i][j] != 'w' && argv[i][j] != 'c'){
	printf("Erreur d'argument: '%s' \n", argv[i]);
	exit(1);
      }
      if(argv[i][j] =='l'){
	opL=1;
      }
      if(argv[i][j] =='w'){
	opW=1;
      }
      if(argv[i][j] =='c'){
	opC=1;
      }
      j++;
    }    
    i++;
  }

  if(opL==0 && opW ==0 && opC==0){
    opL=1;
    opW=1;
    opC=1;
  }

  if (i == argc) {
    printf("Lecture de l'entree standard\n");
    traiter(0,&car,&mots,&lignes);
    if(opC==1){printf("Caracteres : %d  \n",car);}
    if(opW==1){printf("Mots : %d  \n",mots);}
    if(opL==1){printf("Lignes : %d  \n",lignes);}
  }
  while(i<argc){
    if((fc = open(argv[i],O_RDONLY))==-1) {
      perror(argv[i]);
    }
      
    else
      {
	printf("--%s\n",argv[i]);
	traiter(fc,&car,&mots,&lignes);
	totalc+=car;totalw+=mots;totall+=lignes;
	if(opC==1){
	  printf("Caracteres : %d  \n",car);
	}
	if(opW==1){
	  printf("Mots : %d  \n",mots);
	}
	if(opL==1){
	  printf("Lignes : %d  \n",lignes);
	}
	if(car != totalc || mots!=totalw || lignes!=totall){
	  plusieurfichier=1;
	}
	car=0;mots=0;lignes=0;
	close(fc);
      }
     
    i++;
  }
  if(plusieurfichier ==1){
    printf("Total des fichiers : Caracteres : %d / Mots : %d / Lignes : %d \n",totalc,totalw,totall);
  }
  return 0;
}
void decomposition ( double *alpha, double *beta, int min, double value )

/******************************************************************************/
/*
  Purpose:
 
    DECOMPOSITION carries out the decomposition of a subinterval.

  Reference:
 
    Eric Thiemard,
    An Algorithm to Compute Bounds for the Star Discrepancy,
    Journal of Complexity,
    Volume 17, pages 850-880, 2001.
*/
{
  int i;
  double pbetaminp = 1.0;
  double palpha = 1.0;
  double pbeta;
  double delta;
  double *subalpha;
  double *subbeta;
  double *gamma;
  subalpha = (double *) calloc((unsigned) s,sizeof(double));
  subbeta  = (double *) calloc((unsigned) s+1,sizeof(double));
  gamma  = (double *) calloc((unsigned) s+1,sizeof(double));

  for (i=min;i<s;i++)
    pbetaminp *= beta[i];
  pbeta = pbetaminp;
  for (i=0;i<min;i++)
    {
      pbetaminp *= beta[i];
      palpha *= alpha[i];
    }
  pbetaminp -= p;
  delta = pow(pbetaminp/(pbeta*palpha),1.0/(s-min));

  for (i=0;i<min;i++)
    {
      gamma[i] = alpha[i];
      subalpha[i] = gamma[i];
      subbeta[i] = beta[i];
    }
  for (i=min;i<s;i++)
    {
      gamma[i] = delta*beta[i];
      subalpha[i] = alpha[i];
      subbeta[i] = beta[i];
    }
  subbeta[min] = gamma[min];

  value *= delta;
  if (value>p)
    for (i=min;i<s;i++)
      {
	decomposition(subalpha,subbeta,i,value);
	subalpha[i]  = gamma[i];
	subbeta[i]   = beta[i];
	subbeta[i+1] = gamma[i+1];
      }
  else
    for (i=min;i<s;i++)
      {
	traiter(subalpha,subbeta,(i==0)?0:i-1);
	subalpha[i]  = gamma[i];
	subbeta[i]   = beta[i];
	subbeta[i+1] = gamma[i+1];
      }

  traiter(gamma,beta,smin);

  free(gamma);
  free(subalpha);
  free(subbeta);

  return;
}