Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5.     FILE *fdat, *fres;
  6.     fdat=fopen("tennisTournoi2.dat","r");
  7.     fres=fopen("cpecc001.res","w");
  8.  
  9.     int num, nb[21], jw[21], jl[21], i,mat[21],n=1, j, place[21];
  10.     char nom1[21][9], nom2[21][9];
  11.  
  12.     fscanf(fdat,"%4d",&num);
  13.  
  14.     //Lecture
  15.     while(num>0)
  16.     {
  17.         mat[n]=num;
  18.         fscanf(fdat,"%8s%8s%2d%3d%3d",&nom1[n], &nom2[n],&nb[n], &jw[n], &jl[n] );
  19.         place[n]=1;
  20.         n=n+1;
  21.         fscanf(fdat,"%4d",&num);
  22.  
  23.     }
  24.     n=n-1;
  25.  
  26.  
  27.     // Classement en fonction des différents test
  28.     for(i=1;i<=n-1;i++)
  29.     {
  30.  
  31.      for(j=i+1;j<=n;j++)
  32.      {
  33.        if(nb[i] < nb[j])
  34.        {
  35.          place[i]++;
  36.        }
  37.        else if(nb[i] == nb[j])
  38.        {
  39.          if(jw[i]  < jw[j])
  40.          {
  41.            place[i]++;
  42.          }
  43.           else if(jl[i] > jl[j])
  44.           {
  45.            place[i]++;
  46.           }
  47.         }
  48.       }
  49.      }
  50.  
  51.      //tri
  52.      for(i=1;i<=n-1;i++)
  53.     {
  54.       for(j=i+1;j<=n;j++)
  55.       {
  56.         if(strcmp(nom1[i] , nom1[j])>=0)
  57.         {
  58.          strcpy(nom1[0], nom1[i]);
  59.          strcpy(nom1[i], nom1[j]);
  60.          strcpy(nom1[j], nom1[0]);
  61.          strcpy(nom2[0], nom2[i]);
  62.          strcpy(nom2[i], nom2[j]);
  63.          strcpy(nom2[j], nom2[0]);
  64.          nb[0]=nb[i];
  65.          nb[i]=nb[j];
  66.          nb[j]=nb[0];
  67.          place[0]=place[i];
  68.          place[i]=place[j];
  69.          place[j]=place[0];
  70.        }
  71.       }
  72.     }
  73.  
  74.  
  75.  
  76.  for(i=1;i<=n;i++)
  77.     {
  78.         if(strcmp(nom1[i], nom2[i])<0)
  79.         {
  80.           fprintf(fres,"Noms : %8s  %8s\nNombres de victoires : %2d\nPlace obtenue : %d\n\n\n",nom1[i], nom2[i], nb[i], place[i]);
  81.         }
  82.         else
  83.         {
  84.           fprintf(fres,"Noms : %8s  %8s\nNombres de victoires : %2d\nPlace obtenue : %d\n\n\n",nom2[i], nom1[i], nb[i], place[i]);
  85.         }
  86.  
  87.     }
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement