open Printf
open Scanf

(* citeste si tipareste toate sirurile din intrare *)
let rec scanall () =
  scanf " %s" (fun s -> if s <> "" then (printf "%s " s; scanall ()))
;;

(* citeste toate sirurile de intrare si aplica repetat functia f
 * ca si cum le-am pune intr-o lista si am apela List.fold_left f r lst *)
let rec scanfold f r =
  scanf " %s" (fun s -> if s <> "" then scanfold f (f r s) else r)
;;

(* suma lungimilor tuturor sirurilor pana la sfarsitul intrarii *)
(*
print_int (scanfold (fun r s -> r + String.length s) 0)
*)

module M = Map.Make(String)
(* dictionar cu numarul aparitiilor pentru fiecare sir *)
let m = scanfold (fun m s -> 
                  let cnt = try M.find s m with Not_found -> 0
                  in M.add s (cnt+1) m)   M.empty 
;;
M.iter (printf "%s: %d\n") m


This document was generated using caml2html