fork download
  1. let chars s =
  2. let rec aux acc i =
  3. if i < 0 then acc else aux (s.[i] :: acc) (i - 1) in
  4. aux [] (String.length s - 1)
  5. let f877 s =
  6. let rec ccr acc col row = function
  7. | [] -> acc
  8. | c::cs when c = '\n' -> ccr ((c, col, row) :: acc) 0 (row + 1) cs
  9. | c::cs -> ccr ((c, col, row) :: acc) (col + 1) row cs in
  10. let with_pos cs = List.rev (ccr [] 0 0 cs) in
  11. let isspace c =
  12. c = ' ' || c = '\x0c' || c = '\n' || c = '\r' || c = '\t' || c = '\x0b' in
  13. let disp (c, col, row) =
  14. if not (isspace c) then Printf.printf "[%c, %d, %d]\n" c col row in
  15. List.iter disp (with_pos (chars s))
  16. let () = f877 "a b c\n\nd"
  17.  
Success #stdin #stdout 0s 16096KB
stdin
Standard input is empty
stdout
[a, 0, 0]
[b, 2, 0]
[c, 4, 0]
[d, 0, 2]