• + 0 comments

    Here is how to read the stdin for this question in Ocaml:

    let f n arr = 
        (* implementation *)
        
    let () =
        (* first line is parsed as the first arg to f *)
        let num = int_of_string (read_line ()) in
        
        (* the rest until EOF are parsed into an array for second arg *)
        f num (
            let rec aux arr =
                try
                    let input = read_line () in
                        match input with
                        | "" -> arr
                        | a  -> aux (arr @ [int_of_string a])
                with End_of_file -> arr
            in aux [] )