Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 4.57 KB | None | 0 0
  1. #use "AP1utilbis.ml" ;;
  2. #use "AP1saisie5.ml" ;;
  3.  
  4. let get_intver(v_min, v_max : int * int) : int =
  5.   let v : int ref = ref 0 and thend : bool ref = ref false in
  6.   (
  7.     while not(!thend)
  8.     do
  9.       print_string("saisissez votre annee de naissance") ;
  10.       v := read_int() ;
  11.      
  12.       if !v < 2003
  13.       then (print_string("Vous etes trop jeune! Revenez l'an prochain") ; print_newline() ;)
  14.       else
  15.         if !v > 2005
  16.       then (print_string("Vous etes trop trop vieux! Rien a faire la..") ; print_newline() ;);
  17.      
  18.       thend := ( !v >= v_min && !v <= v_max);
  19.            
  20.     done;
  21.    
  22.    !v;
  23.   )
  24. ;;
  25.  
  26. let get_id() : int =
  27.   let v : int ref = ref 0 and thend : bool ref = ref false in
  28.   (
  29.     while not( !thend)
  30.     do
  31.       print_string("saisissez votre numero de licence: ") ;
  32.       v := read_int() ;
  33.       thend := ( !v >= 0) ;
  34.     done ;
  35.     !v ;
  36.   )
  37. ;;
  38.  
  39. let get_poids() : int =
  40.   let v : int ref = ref 0 and thend : bool ref = ref false in
  41.   (
  42.     while not( !thend)
  43.     do
  44.       print_string("saisissez votre poids: ") ;
  45.       v := read_int() ;
  46.       thend := ( !v >= 0) ;
  47.     done ;
  48.     !v ;
  49.   )
  50. ;;
  51.  
  52. let get_name() : string =
  53.  print_string("saisissez votre nom: ");
  54.   let nom : string = read_line() in
  55.  
  56.  
  57.   nom;
  58. ;;
  59.  
  60.  
  61.  
  62. type t_judoka = {nom : string ; yob : int ; id : int ; poids : int;};;
  63. (* yob = year of birth, id = identification*)
  64.  
  65.  
  66. let cat_weight_tab = [|46 ; 50 ; 55 ; 60 ; 66 ; 73 ; 81 ; 90 ; 90|];;
  67. let cat_playerNum_tab = [|1 ; 1 ; 3 ; 2 ; 3 ; 0 ; 5 ; 0 ; 3|];;
  68.  
  69.  
  70. let get_judoka() : t_judoka =
  71. {nom = get_name() ; yob = get_intver(2003, 2005); id = get_id() ; poids = get_poids()}
  72. ;;
  73.  
  74.  
  75. let registration_aux(b : int) : int =
  76.   let m : t_judoka ref = ref {nom = "0" ; yob = 0; id = 0 ; poids = b}  in
  77.   let pos : int ref = ref 1 in
  78.  
  79. (
  80.   for i = 1 to 8
  81.      do
  82.         if !m.poids < cat_weight_tab.(i-1)
  83.         then
  84.           pos := !pos
  85.         else
  86.           if !m.poids > cat_weight_tab.(i-1)
  87.           then pos := !pos + 1
  88.           else
  89.             if !m.poids > 90
  90.             then pos := 8;
  91.        
  92.   done ;
  93.  
  94.   !pos-1;
  95.  
  96.  
  97.  
  98. )
  99.  ;;
  100.  
  101.  let registration() : unit =
  102.   let poids : t_judoka = get_judoka() in
  103.   let m : int ref = ref poids.poids in
  104.   let pos : int = registration_aux(!m) in
  105.   cat_playerNum_tab.(pos) <- cat_playerNum_tab.(pos) + 1;
  106.   ;;
  107.  
  108.    
  109. let registration_tab() : (int*int) array =
  110.     let v : (int*int) array = arr_make(9, (0,0)) in
  111.     (
  112.       for i = 1 to 9
  113.       do
  114.       v.(i-1) <- (cat_weight_tab.(i-1), cat_playerNum_tab.(i-1));
  115.       done ;  
  116.       v;
  117.     )
  118. ;;
  119.  
  120.  
  121.  
  122.  let get_registration(): (int*int) array =
  123.    let m : t_judoka ref = ref {nom = "0" ; yob = 0; id = 0 ; poids = 0} in
  124.    let fin : bool ref = ref false in
  125.  
  126.    (
  127.    while not(!fin)
  128.    do
  129.          m :=  get_judoka();
  130.          registration(!m.poids);
  131.          if !m.nom = "@"
  132.          then fin := true
  133.          else
  134.            fin := false;
  135.    done;
  136.    registration_tab();
  137.    )
  138.  ;;
  139.  
  140. let counter() : bool =
  141.  let count : int ref = ref 0 in
  142.    (
  143.      for i = 1 to 9
  144.      do
  145.        if
  146.          (cat_playerNum_tab.(i-1) > 0) && not(!count > 2)
  147.        then
  148.          count := (cat_playerNum_tab.(i-1) + !count);  
  149.      done;
  150.  
  151.          (!count > 2) ;
  152.    )
  153. ;;
  154. let failcount() : bool =
  155.   if not(counter())
  156.   then
  157.     failwith "pas assez d'inscrits"
  158.   else
  159.     counter()
  160. ;;
  161.  
  162.  
  163. let grouping() : int array =
  164.  
  165. (
  166.    for i = 1 to 8
  167.    do
  168.       if
  169.         (cat_playerNum_tab.(i-1) < 3) && failcount()
  170.       then
  171.         (cat_playerNum_tab.(i) <- cat_playerNum_tab.(i-1) + cat_playerNum_tab.(i);
  172.          cat_playerNum_tab.(i-1) <- 0)
  173.       else
  174.         if
  175.           cat_playerNum_tab.(8) < 3
  176.         then
  177.           (cat_playerNum_tab.(7) <- cat_playerNum_tab.(8) + cat_playerNum_tab.(7);
  178.            cat_playerNum_tab.(8) <- 0)
  179.         ;
  180.    done ;
  181.    cat_playerNum_tab;
  182. )
  183. ;;
  184.  
  185.  
  186.  
  187. let aux_cat(num : int) : int =
  188.   let pos : int ref = ref (registration_aux(num)) in
  189.   (
  190.     for i = 1 to 8
  191.     do
  192.       if cat_playerNum_tab.(!pos) < 1
  193.       then
  194.         pos := !pos + 1
  195.       else
  196.         pos := !pos ;
  197.     done;
  198.     !pos;
  199.   )
  200.  
  201.   ;;
  202.  
  203. let category() : unit =
  204.   let m : t_judoka = get_judoka() in
  205.   let g : int = aux_cat(m.poids) in
  206.    
  207.   if (m.poids > 1) && (g < 8)
  208.   then
  209.     (
  210.      print_string("-");
  211.      print_string(string_of_int(cat_weight_tab.(g)));
  212.      print_string(" ");
  213.      print_newline()
  214. )
  215.   else
  216.     (
  217.      print_string(string_of_int(cat_weight_tab.(g)));
  218.      print_string("+");
  219.      print_string(" ");
  220.      print_newline()
  221.     )
  222.   ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement