fork download
  1. (* Opennings *)
  2. open List;;
  3. (* Common part *)
  4. let (|>) x f = f x
  5. let identity = fun x -> x
  6.  
  7. let flip f y x = f x y
  8.  
  9. let readInStr _ = Scanf.scanf "%d " identity
  10. let readIntLn _ = Scanf.scanf "%d\n" identity
  11. (* Programme *)
  12. let rec input_list = function
  13. 0 -> []
  14. | n -> (Scanf.scanf "%s %s %d" (fun x y t -> (x, y, t)) ) :: (input_list (n-1))
  15. ;;
  16. let rec print_list =
  17. let s x = function ( x,y, t) -> x^" "^y
  18. in function
  19. [] -> ()
  20. | x :: xs -> print_string x; print_list xs
  21. ;;
  22. let mapf f =
  23. let rec mapf' = function
  24. [] -> []
  25. | l::ls -> match f l ls
  26. with None -> mapf' ls
  27. | Some x -> x:: mapf' ls
  28. in mapf';;
  29. let exic p =
  30. let rec exic' = function
  31. [] -> false
  32. | x:: xs -> if p x then true else exic' xs
  33. in exic'
  34. sample =
  35. let rec f d l = function
  36. [] ->
  37. | x ::xs -> match (l, x )
  38. with( (a,b,t1) , (x,y,t) ) when a<>y or b<>x <> (t1-t = 0) -> f d l xs
  39. | ((a,b,t1),(a1,b1,t) ) ->
  40. if (t1-t) > d
  41. then None
  42. else Some (a,b)
  43. in mapf f
  44.  
  45. let del_rep l =
  46. let c = ref 0
  47. in let f l ls = if exic (fun x ->match (x , l) with( (a,b), (c,d) )-> ((a=c)&&(b=d)) or ((a=d)&&(b=c)) ) ls then None else (inc c; Some l)
  48. in (mapf f l , !c)
  49. let main () =
  50. let n = readInStr ()
  51. in let d = readIntLn()
  52. in let res = input_list n |> sample |> del_rep in
  53. print_int (snd res);
  54. print_list (fst res);
  55. ;;
  56. main()
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
File "prog.ml", line 37, characters 1-2:
Syntax error
stdout
Standard output is empty