Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.37 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #pragma warning (disable : 4996)
  5.  
  6. #define MAXTOURS 10 // Nombre maximum de tours
  7. #define MAXEPREUVES 16 // Nombre maximal d'epreuves
  8. #define MAXEQUIPE 32 // Nombre d'equipe maximale
  9. #define NBPATINEURSPAREQUIPES 3 // Nombre de patineurs par equipes
  10. #define NBEQUIPEPAREPREUVES 2 // Nombre d'equipes par epreuves
  11. #define LGMOT 30 // Nombre maximal de mot
  12. #define NUMDOSSARD 101 // Numero dossard
  13. #define NBCARMAX 80 // Nombre maximal de caracteres
  14.  
  15. typedef struct {
  16.     unsigned int numeroTour;
  17.     float temps;
  18. } Mesure;
  19.  
  20. typedef struct {
  21.     char nom[LGMOT + 1];
  22.     unsigned int dossard;
  23.     Mesure temps[MAXTOURS];
  24.     unsigned int tourEffectuer;
  25. } Patineur;
  26.  
  27. typedef struct {
  28.     char pays[LGMOT + 1];
  29.     Patineur data[NBPATINEURSPAREQUIPES];
  30. } Equipe;
  31.  
  32. typedef struct {
  33.     unsigned int nbTour;
  34. } Course;
  35.  
  36. typedef struct {
  37.     Course numCourse[MAXEPREUVES];
  38. } Epreuve;
  39.  
  40. typedef struct {
  41.     Epreuve epreuves[MAXEPREUVES];
  42.     Equipe tableauEquipe[MAXEQUIPE];
  43. } Competition;
  44.  
  45. void inscrire_equipe(Competition* competition, int* cptEquipeInscrites, int* cptNbPatineurs) {
  46.     Equipe equipe;
  47.     char mot[LGMOT + 1];
  48.     scanf("%s", mot);
  49.     strcpy(equipe.pays, mot);
  50.  
  51.     //Dans une equipe, on inscrit les patineurs
  52.     for (int i = 0; i < NBPATINEURSPAREQUIPES; i++) {
  53.         Patineur p;
  54.         char mot[NBCARMAX + 1];
  55.         p.dossard = NUMDOSSARD + *cptNbPatineurs;
  56.         scanf("%s", mot);
  57.         strcpy(p.nom, mot);
  58.         equipe.data[i] = p;
  59.         printf("inscription dossard %d\n", p.dossard);
  60.         (*cptNbPatineurs)++;
  61.  
  62.     }
  63.  
  64.     //On enregistre l'equipe dans la competition
  65.     competition->tableauEquipe[*cptEquipeInscrites] = equipe;
  66.     (*cptEquipeInscrites)++;
  67. }
  68. void afficher_equipes(const Competition* competition, int* cptEquipeInscrites) {
  69.     int i = 0;
  70.     for (int i = 0; i < *cptEquipeInscrites; i++) {
  71.         printf("%s ", competition->tableauEquipe[i].pays);
  72.         for (int j = 0; j < NBPATINEURSPAREQUIPES; j++) {
  73.             printf("%s %d ", competition->tableauEquipe[i].data[j].nom, competition->tableauEquipe[i].data[j].dossard);
  74.         }
  75.         printf("\n");
  76.     }
  77. }
  78.  
  79. void enregistrer_temps(Competition* competition ) {
  80.     int dossard = 0;
  81.     int tour = 0;
  82.     float temps = 0;
  83.     int indiceEquipe = 0;
  84.     int indicePatineur = 0;
  85.     scanf("%d %d %f", &dossard, &tour, &temps);
  86.     int numInscrit = dossard - NUMDOSSARD +1;
  87.     indiceEquipe = numInscrit / 3;
  88.     indicePatineur = numInscrit % 3;
  89.     int o = 0;
  90.     if (competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer < 1)
  91.         competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer = o;
  92.     int indiceTour = 0;
  93.     indiceTour = competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer;
  94.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[indiceTour].numeroTour = tour;
  95.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[indiceTour].temps = temps;
  96.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer++;
  97. }
  98.  
  99. void afficher_temps(const Competition* competition) {
  100.     int dossard = 0;
  101.     int indiceEquipe = 0;
  102.     int indicePatineur = 0;
  103.     scanf("%d", &dossard);
  104.     int numInscrit = dossard - NUMDOSSARD + 1;
  105.     indiceEquipe = numInscrit / 3;
  106.     indicePatineur = numInscrit % 3;
  107.     int tourEffectuer = competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer;
  108.     for (int i = 0; i < tourEffectuer; i++) {
  109.         printf("%s ", competition->tableauEquipe[indiceEquipe].pays);
  110.         printf("%d ", competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer);
  111.         printf("%s ", competition->tableauEquipe[indiceEquipe].data[indicePatineur].nom);
  112.         printf("%.1f ",competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps->temps);
  113.         printf("\n");
  114.     }
  115. }
  116.  
  117.  
  118. int main() {
  119.     int* cptEquipesInscrites = 0;
  120.     int* cptNbPatineurs = 0;
  121.     Competition c;
  122.     Competition* competition = &c;
  123.     Course crs;
  124.     Course* course = &crs;
  125.  
  126.  
  127.     char mot[LGMOT + 1];
  128.     while (1) {
  129.         scanf("%s", mot);
  130.         // si la commande est "definir_parcours"
  131.         if (strcmp(mot, "inscrire_equipe") == 0) {
  132.             inscrire_equipe(&c, &cptEquipesInscrites, &cptNbPatineurs);
  133.         }
  134.         if (strcmp(mot, "afficher_equipes") == 0) {
  135.             afficher_equipes(&c, &cptEquipesInscrites);
  136.         }
  137.         if (strcmp(mot, "enregistrer_temps") == 0) {
  138.             enregistrer_temps(&c);
  139.         }
  140.         if (strcmp(mot, "afficher_temps") == 0) {
  141.             afficher_temps(&c);
  142.         }
  143.         if (strcmp(mot, "exit") == 0) {
  144.             exit(0);
  145.         }
  146.     }
  147.     return 0;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement