Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 4.54 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(judoboi : t_judoka) : unit =
  102.   let m : int ref = ref judoboi.poids in
  103.   let pos : int = registration_aux(!m) in
  104.   cat_playerNum_tab.(pos) <- cat_playerNum_tab.(pos) + 1;
  105.   ;;
  106.  
  107.    
  108. let registration_tab() : (int*int) array =
  109.     let v : (int*int) array = arr_make(9, (0,0)) in
  110.     (
  111.       for i = 1 to 9
  112.       do
  113.       v.(i-1) <- (cat_weight_tab.(i-1), cat_playerNum_tab.(i-1));
  114.       done ;  
  115.       v;
  116.     )
  117. ;;
  118.  
  119.  
  120.  
  121.  let get_registration(): (int*int) array =
  122.    let m : t_judoka ref = ref {nom = "0" ; yob = 0; id = 0 ; poids = 0} in
  123.    let fin : bool ref = ref false in
  124.  
  125.    (
  126.    while not(!fin)
  127.    do
  128.          m :=  get_judoka();
  129.          registration(!m);
  130.          if !m.nom = "@"
  131.          then fin := true
  132.          else
  133.            fin := false;
  134.    done;
  135.    registration_tab();
  136.    )
  137.  ;;
  138.  
  139. let counter() : bool =
  140.  let count : int ref = ref 0 in
  141.    (
  142.      for i = 1 to 9
  143.      do
  144.        if
  145.          (cat_playerNum_tab.(i-1) > 0) && not(!count > 2)
  146.        then
  147.          count := (cat_playerNum_tab.(i-1) + !count);  
  148.      done;
  149.  
  150.          (!count > 2) ;
  151.    )
  152. ;;
  153. let failcount() : bool =
  154.   if not(counter())
  155.   then
  156.     failwith "pas assez d'inscrits"
  157.   else
  158.     counter()
  159. ;;
  160.  
  161.  
  162. let grouping() : int array =
  163.  
  164. (
  165.    for i = 1 to 8
  166.    do
  167.       if
  168.         (cat_playerNum_tab.(i-1) < 3) && failcount()
  169.       then
  170.         (cat_playerNum_tab.(i) <- cat_playerNum_tab.(i-1) + cat_playerNum_tab.(i);
  171.          cat_playerNum_tab.(i-1) <- 0)
  172.       else
  173.         if
  174.           cat_playerNum_tab.(8) < 3
  175.         then
  176.           (cat_playerNum_tab.(7) <- cat_playerNum_tab.(8) + cat_playerNum_tab.(7);
  177.            cat_playerNum_tab.(8) <- 0)
  178.         ;
  179.    done ;
  180.    cat_playerNum_tab;
  181. )
  182. ;;
  183.  
  184.  
  185.  
  186. let aux_cat(num : int) : int =
  187.   let pos : int ref = ref (registration_aux(num)) in
  188.   (
  189.     for i = 1 to 8
  190.     do
  191.       if cat_playerNum_tab.(!pos) < 1
  192.       then
  193.         pos := !pos + 1
  194.       else
  195.         pos := !pos ;
  196.     done;
  197.     !pos;
  198.   )
  199.  
  200.   ;;
  201.  
  202. let category() : unit =
  203.   let m : t_judoka = get_judoka() in
  204.   let g : int = aux_cat(m.poids) in
  205.    
  206.   if (m.poids > 1) && (g < 8)
  207.   then
  208.     (
  209.      print_string("-");
  210.      print_string(string_of_int(cat_weight_tab.(g)));
  211.      print_string(" ");
  212.      print_newline()
  213. )
  214.   else
  215.     (
  216.      print_string(string_of_int(cat_weight_tab.(g)));
  217.      print_string("+");
  218.      print_string(" ");
  219.      print_newline()
  220.     )
  221.   ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement