Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.17 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.     float temps;
  21. } Mesure;
  22.  
  23. typedef struct {
  24.     char nom[LGMOT + 1];
  25.     unsigned int dossard;
  26.     Mesure temps[MAXTOURS];
  27.     unsigned int tourEffectuer;
  28. } Patineur;
  29.  
  30. typedef struct {
  31.     char pays[LGMOT + 1];
  32.     Patineur data[NBPATINEURSPAREQUIPES];
  33. } Equipe;
  34.  
  35. typedef struct {
  36.     unsigned int nbTour;
  37. } Course;
  38.  
  39. typedef struct {
  40.     Course numCourse[MAXEPREUVES];
  41. } Epreuve;
  42.  
  43. typedef struct {
  44.     Epreuve epreuves[MAXEPREUVES];
  45.     Equipe tableauEquipe[MAXEQUIPE];
  46. } Competition;
  47.  
  48.  
  49. int definition_parcours(Competition* tour) {
  50.     scanf("%d", &tour);
  51.     assert(tour >= MINTOURS && tour <= MAXTOURS);
  52.     return tour;
  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.     scanf("%s", equipe.pays);
  63.     //Dans une equipe, on inscrit les patineurs
  64.     for (int i = 0; i < NBPATINEURSPAREQUIPES; i++) {
  65.         Patineur p;
  66.         char mot[NBCARMAX + 1];
  67.         p.dossard = NUMDOSSARD + *cptNbPatineurs;
  68.         scanf("%s", mot);
  69.         strcpy(p.nom, mot);
  70.         equipe.data[i] = p;
  71.         printf("inscription dossard %d\n", p.dossard);
  72.         (*cptNbPatineurs)++;
  73.  
  74.     }
  75.  
  76.     //On enregistre l'equipe dans la competition
  77.     competition->tableauEquipe[*cptEquipeInscrites] = equipe;
  78.     (*cptEquipeInscrites)++;
  79. }
  80. void afficher_equipes(const Competition* competition, int* cptEquipeInscrites) {
  81.     int i = 0;
  82.     for (int i = 0; i < *cptEquipeInscrites; i++) {
  83.         printf("%s ", competition->tableauEquipe[i].pays);
  84.         for (int j = 0; j < NBPATINEURSPAREQUIPES; j++) {
  85.             printf("%s %d ", competition->tableauEquipe[i].data[j].nom, competition->tableauEquipe[i].data[j].dossard);
  86.         }
  87.         printf("\n");
  88.     }
  89. }
  90.  
  91. void enregistrer_temps(Competition* competition) {
  92.     int dossard = 0;
  93.     unsigned int tour = 0;
  94.     float temps = 0;
  95.     int indiceEquipe = 0;
  96.     int indicePatineur = 0;
  97.     int p = 0;
  98.     scanf("%d %d %f", &dossard, &tour, &temps);
  99.     int numInscrit = dossard - NUMDOSSARD;
  100.     indiceEquipe = numInscrit / 3;
  101.     indicePatineur = numInscrit % 3;
  102.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer = tour;
  103.     competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[tour].temps = temps;
  104.  
  105. }
  106.  
  107. void afficher_temps(const Competition* competition) {
  108.     int dossard = 0;
  109.     int indiceEquipe = 0;
  110.     int indicePatineur = 0;
  111.     scanf("%d", &dossard);
  112.     int numInscrit = dossard - NUMDOSSARD;
  113.     indiceEquipe = numInscrit / 3;
  114.     indicePatineur = numInscrit % 3;
  115.     int tourEffectuer = competition->tableauEquipe[indiceEquipe].data[indicePatineur].tourEffectuer;
  116.     for (int i = 0; i < tourEffectuer; i++) {
  117.         printf("%s ", competition->tableauEquipe[indiceEquipe].pays);
  118.         printf("%s ", competition->tableauEquipe[indiceEquipe].data[indicePatineur].nom);
  119.         printf("%.1f ", competition->tableauEquipe[indiceEquipe].data[indicePatineur].temps[i + 1].temps);
  120.         printf("\n");
  121.     }
  122. }
  123.  
  124. void afficher_temps_equipes(const Competition* competition) {
  125.     int course = 0;
  126.     int nbEquipe = 0;
  127.     float tps = 0;
  128.     scanf("%d", &course);
  129.     for (int i = 0; i < NBEQUIPEPAREPREUVES; i++) {
  130.         float temps = 0;
  131.         int a = 0;
  132.         for (int j = 0; j < NBPATINEURSPAREQUIPES; j++) {
  133.             if (temps < competition->tableauEquipe[i].data[j].temps[course].temps) {
  134.                 temps = competition->tableauEquipe[i].data[j].temps[course].temps;
  135.             }
  136.             if (competition->tableauEquipe[i].data[j].temps[course].temps < 0) {
  137.                 a = 1;
  138.             }
  139.         }
  140.         if (a == 1) {
  141.             printf("Temps indisponible pour l'equipe %s\n", competition->tableauEquipe[i].pays);
  142.         }
  143.         else {
  144.             printf("%s ", competition->tableauEquipe[i].pays);
  145.             printf("%.1f ", temps);
  146.             printf("\n");
  147.         }
  148.     }
  149. }
  150.  
  151. void detection_fin_poursuite(Competition* competition, int tour) {
  152.     int nbtour = tour;
  153.     int equip = 0;
  154.     for (int i = 0; i < NBEQUIPEPAREPREUVES; i++) {
  155.         float temps = 0;
  156.         int non = 0;
  157.         for (int j = 0; j < NBPATINEURSPAREQUIPES; j++) {
  158.             if (temps < competition->tableauEquipe[i].data[j].temps[tour].temps) {
  159.                 temps = competition->tableauEquipe[i].data[j].temps[tour].temps;
  160.             }
  161.            
  162.         }
  163.        
  164.             printf("%s ", competition->tableauEquipe[i].pays);
  165.             printf("%.1f ", temps);
  166.             printf("\n");
  167.         }
  168.     }
  169. }
  170. int main() {
  171.     int* cptEquipesInscrites = 0;
  172.     int* cptNbPatineurs = 0;
  173.     Competition c;
  174.     Competition* competition = &c;
  175.     Course crs;
  176.     Course* course = &crs;
  177.     int tour = 0;
  178.     int nbEp = 0;
  179.     int patMax = NBPATINEURSPAREQUIPES;
  180.     char mot[LGMOT + 1];
  181.     int detect = 0;
  182.     while (1) {
  183.         scanf("%s", mot);
  184.         // si la commande est "definir_parcours"
  185.         if (strcmp(mot, "inscrire_equipe") == 0) {
  186.             inscrire_equipe(&c, &cptEquipesInscrites, &cptNbPatineurs);
  187.         }
  188.         // si la commande est "definir_parcours"
  189.         if (strcmp(mot, "definir_parcours") == 0) {
  190.             // apppeler la fonction definition_parcours
  191.             tour = definition_parcours(tour);
  192.         }
  193.         // si la commande est "definir_nombre_epreuves"
  194.         if (strcmp(mot, "definir_nombre_epreuves") == 0) {
  195.             // apppeler la fonction definition_parcours
  196.             definition_nb_epreuves(nbEp);
  197.         }
  198.         if (strcmp(mot, "afficher_equipes") == 0) {
  199.             afficher_equipes(&c, &cptEquipesInscrites);
  200.         }
  201.         if (strcmp(mot, "enregistrer_temps") == 0) {
  202.             detect++;
  203.             enregistrer_temps(&c);
  204.             if (detect == (NBPATINEURSPAREQUIPES * NBEQUIPEPAREPREUVES * tour)) {
  205.                 detection_fin_poursuite(&c, tour);
  206.             }
  207.         }
  208.         if (strcmp(mot, "afficher_temps") == 0) {
  209.             afficher_temps(&c);
  210.         }
  211.         if (strcmp(mot, "afficher_temps_equipes") == 0) {
  212.             afficher_temps_equipes(&c);
  213.         }
  214.         if (strcmp(mot, "exit") == 0) {
  215.             exit(0);
  216.         }
  217.     }
  218.     return 0;
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement