Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- FILE *fdat, *fres;
- fdat=fopen("tennisTournoi2.dat","r");
- fres=fopen("cpecc001.res","w");
- int num, nb[21], jw[21], jl[21], i,mat[21],n=1, j, place[21];
- char nom1[21][9], nom2[21][9];
- fscanf(fdat,"%4d",&num);
- //Lecture
- while(num>0)
- {
- mat[n]=num;
- fscanf(fdat,"%8s%8s%2d%3d%3d",&nom1[n], &nom2[n],&nb[n], &jw[n], &jl[n] );
- place[n]=1;
- n=n+1;
- fscanf(fdat,"%4d",&num);
- }
- n=n-1;
- // Classement en fonction des différents test
- for(i=1;i<=n-1;i++)
- {
- for(j=i+1;j<=n;j++)
- {
- if(nb[i] < nb[j])
- {
- place[i]++;
- }
- else if(nb[i] == nb[j])
- {
- if(jw[i] < jw[j])
- {
- place[i]++;
- }
- else if(jl[i] > jl[j])
- {
- place[i]++;
- }
- }
- }
- }
- //tri
- for(i=1;i<=n-1;i++)
- {
- for(j=i+1;j<=n;j++)
- {
- if(strcmp(nom1[i] , nom1[j])>=0)
- {
- strcpy(nom1[0], nom1[i]);
- strcpy(nom1[i], nom1[j]);
- strcpy(nom1[j], nom1[0]);
- strcpy(nom2[0], nom2[i]);
- strcpy(nom2[i], nom2[j]);
- strcpy(nom2[j], nom2[0]);
- nb[0]=nb[i];
- nb[i]=nb[j];
- nb[j]=nb[0];
- place[0]=place[i];
- place[i]=place[j];
- place[j]=place[0];
- }
- }
- }
- for(i=1;i<=n;i++)
- {
- if(strcmp(nom1[i], nom2[i])<0)
- {
- fprintf(fres,"Noms : %8s %8s\nNombres de victoires : %2d\nPlace obtenue : %d\n\n\n",nom1[i], nom2[i], nb[i], place[i]);
- }
- else
- {
- fprintf(fres,"Noms : %8s %8s\nNombres de victoires : %2d\nPlace obtenue : %d\n\n\n",nom2[i], nom1[i], nb[i], place[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement