Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <assert.h>
  5. #include <math.h>
  6. #include <string.h>
  7. #pragma warning (disable : 4996)
  8.  
  9. #define MINTOURS 2 //Nombre minimal de tours
  10. #define MAXTOURS 10 // Nombre maximum de tours
  11. #define MINEPREUVES 1 //Nombre Maximal d'epreuves
  12. #define MAXEPREUVES 16 // Nombre maximal d'epreuves
  13. #define MAXEQUIPE 32 // Nombre d'equipe maximale
  14. #define NBPATINEURSPAREQUIPES 3 // Nombre de patineurs par equipes
  15. #define NBEQUIPEPAREPREUVES 2 // Nombre d'equipes par epreuves
  16. #define LGMOT 30 // Nombre maximal de mot
  17. #define NUMDOSSARD 101 // Numero dossard
  18. #define NBCARMAX 80 // Nombre maximal de caracteres
  19. typedef struct {
  20.     unsigned int numeroTour;
  21.     float temps;
  22. } Mesure;
  23.  
  24. typedef struct {
  25.     char nom[LGMOT + 1];
  26.     unsigned int dossard;
  27.     Mesure temps[MAXTOURS];
  28.     unsigned int tourEffectuer;
  29. } Patineur;
  30.  
  31. typedef struct {
  32.     char pays[LGMOT + 1];
  33.     Patineur data[NBPATINEURSPAREQUIPES];
  34. } Equipe;
  35.  
  36. typedef struct {
  37.     unsigned int nbTour;
  38. } Course;
  39.  
  40. typedef struct {
  41.     Course numCourse[MAXEPREUVES];
  42. } Epreuve;
  43.  
  44. typedef struct {
  45.     Epreuve epreuves[MAXEPREUVES];
  46.     Equipe tableauEquipe[MAXEQUIPE];
  47. } Competition;
  48.  
  49.  
  50. void definition_parcours(int tour) {
  51.     scanf("%d", &tour);
  52.     assert(tour >= MINTOURS && tour <= MAXTOURS);
  53. }
  54.  
  55. void definition_nb_epreuves(int nbEp) {
  56.     scanf("%d", &nbEp);
  57.     assert(nbEp >= MINEPREUVES && nbEp <= MAXEPREUVES);
  58. }
  59.  
  60. void inscrire_equipe(Competition* competition, int* cptEquipeInscrites, int* cptNbPatineurs) {
  61.     Equipe equipe;
  62.     char mot[LGMOT + 1];
  63.     scanf("%s", mot);
  64.     strcpy(equipe.pays, mot);
  65.  
  66.     //Dans une equipe, on inscrit les patineurs
  67.     for (int i = 0; i < NBPATINEURSPAREQUIPES; i++) {
  68.         Patineur p;
  69.         char mot[NBCARMAX + 1];
  70.         p.dossard = NUMDOSSARD + *cptNbPatineurs;
  71.         scanf("%s", mot);
  72.         strcpy(p.nom, mot);
  73.         equipe.data[i] = p;
  74.         printf("inscription dossard %d\n", p.dossard);
  75.         (*cptNbPatineurs)++;
  76.  
  77.     }
  78.  
  79.     //On enregistre l'equipe dans la competition
  80.     competition->tableauEquipe[*cptEquipeInscrites] = equipe;
  81.     (*cptEquipeInscrites)++;
  82. }
  83. void afficher_equipes(const Competition* competition, int* cptEquipeInscrites) {
  84.     int i = 0;
  85.     for (int i = 0; i < *cptEquipeInscrites; i++) {
  86.         printf("%s ", competition->tableauEquipe[i].pays);
  87.         for (int j = 0; j < NBPATINEURSPAREQUIPES; j++) {
  88.             printf("%s %d ", competition->tableauEquipe[i].data[j].nom, competition->tableauEquipe[i].data[j].dossard);
  89.         }
  90.         printf("\n");
  91.     }
  92. }
  93.  
  94. void enregistrer_temps(Competition* competition) {
  95.     int dossard = 0;
  96.     unsigned int tour = 0;
  97.     float temps = 0;
  98.     int indiceEquipe = 0;
  99.     int indicePatineur = 0;
  100.     int p = 0;
  101.     scanf("%d %d %f", &dossard, &tour, &temps);
  102.     int numInscrit = dossard - NUMDOSSARD;
  103.     indiceEquipe = numInscrit / 3;
  104.     indicePatineur = numInscrit % 3;
  105.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer = tour;
  106.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[tour].numeroTour = tour;
  107.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[tour].temps = temps;
  108.  
  109. }
  110.  
  111. void afficher_temps(const Competition* competition) {
  112.     int dossard = 0;
  113.     int indiceEquipe = 0;
  114.     int indicePatineur = 0;
  115.     scanf("%d", &dossard);
  116.     int numInscrit = dossard - NUMDOSSARD;
  117.     indiceEquipe = numInscrit / 3;
  118.     indicePatineur = numInscrit % 3;
  119.     int tourEffectuer = competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer;
  120.     for (int i = 0; i < tourEffectuer; i++) {
  121.         printf("%s ", competition->tableauEquipe[indiceEquipe].pays);
  122.         printf("%d ", competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[i + 1].numeroTour);
  123.         printf("%s ", competition->tableauEquipe[indiceEquipe].data[indicePatineur].nom);
  124.         printf("%.1f ", competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[i + 1].temps);
  125.         printf("\n");
  126.     }
  127. }
  128.  
  129. void afficher_temps_equipes(Competition* competition) {
  130.     int course = 0;
  131.     int nbEquipe = 0;
  132.     float tps = 0;
  133.     scanf("%d", &course);
  134.     for (int i = 0; i < NBEQUIPEPAREPREUVES; i++) {
  135.         float temps = 0;
  136.         int a = 0;
  137.         for (int j = 0; j < NBPATINEURSPAREQUIPES; j++) {
  138.             if (temps < competition->tableauEquipe[i].data[j].temps[course].temps) {
  139.                 temps = competition->tableauEquipe[i].data[j].temps[course].temps;
  140.             }
  141.             if (competition->tableauEquipe[i].data[j].temps[course].temps < 0) {
  142.                 a = 1;
  143.             }
  144.         }
  145.         if (a == 1) {
  146.             printf("Temps indisponible pour l'equipe %s\n", competition->tableauEquipe[i].pays);
  147.         }
  148.         else {
  149.             printf("%s ", competition->tableauEquipe[i].pays);
  150.             printf("%.1f ", temps);
  151.             printf("\n");
  152.         }
  153.     }
  154. }
  155.  
  156.  
  157. int main() {
  158.     int* cptEquipesInscrites = 0;
  159.     int* cptNbPatineurs = 0;
  160.     Competition c;
  161.     Competition* competition = &c;
  162.     Course crs;
  163.     Course* course = &crs;
  164.     int indiceTour = 0;
  165.     int tour = 0;
  166.     int nbEp = 0;
  167.  
  168.     char mot[LGMOT + 1];
  169.     while (1) {
  170.         scanf("%s", mot);
  171.         // si la commande est "definir_parcours"
  172.         if (strcmp(mot, "inscrire_equipe") == 0) {
  173.             inscrire_equipe(&c, &cptEquipesInscrites, &cptNbPatineurs);
  174.         }
  175.         // si la commande est "definir_parcours"
  176.         if (strcmp(mot, "definir_parcours") == 0) {
  177.             // apppeler la fonction definition_parcours
  178.             definition_parcours(tour);
  179.         }
  180.         // si la commande est "definir_nombre_epreuves"
  181.         if (strcmp(mot, "definir_nombre_epreuves") == 0) {
  182.             // apppeler la fonction definition_parcours
  183.             definition_nb_epreuves(nbEp);
  184.         }
  185.  
  186.         if (strcmp(mot, "afficher_equipes") == 0) {
  187.             afficher_equipes(&c, &cptEquipesInscrites);
  188.         }
  189.         if (strcmp(mot, "enregistrer_temps") == 0) {
  190.             enregistrer_temps(&c);
  191.         }
  192.         if (strcmp(mot, "afficher_temps") == 0) {
  193.             afficher_temps(&c);
  194.         }
  195.         if (strcmp(mot, "afficher_temps_equipes") == 0) {
  196.             afficher_temps_equipes(&c);
  197.         }
  198.         if (strcmp(mot, "exit") == 0) {
  199.             exit(0);
  200.         }
  201.     }
  202.     return 0;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement