1 / 4
Oct 2007

It is very convenient to solve task ONP using streams:

type expr =
    Atom of char
  | Par  of expr
  | Op   of char * expr * expr
let rec parse = parser
    [< ''('; r = parse_op; '')' >] -> Par r
  | [< 'ch >]                      -> Atom ch
and     parse_op = parser
    [< l = parse; 'op; r = parse >] -> Op (op, l, r)
let rec output_rpn = function
    Atom ch      -> print_char ch
  | Par expr     -> output_rpn expr
  | Op (op, e1, e2) -> output_rpn e1; output_rpn e2; print_char op
let n = int_of_string (input_line stdin) in
for i = 1 to n do
  output_rpn (parse (Stream.of_string (input_line stdin))) ;
  print_newline ()
done ;;

But I have got compile error (syntax error). Command to compile it: ocamlopt -pp "camlp4o" task.ml.

  • created

    Oct '07
  • last reply

    Nov '14
  • 3

    replies

  • 1.2k

    views

  • 4

    users

[quote="dream_designer"]It is very convenient to solve task ONP using streams:

snip

But I have got compile error (syntax error). Command to compile it: ocamlopt -pp "camlp4o" task.ml.[/quote]
I don't know Ocaml well and I don't know what consequences that would have for other solutions. I have to be very careful with such modifications.

In your case, isn't it possible to do the preprocessing on your machine and submit the preprocessed version to SPOJ?

1 month later

yes, preprocessing locally should work:

camlp4o pr_o.cmo file.ml > newfile.ml
ocamlopt -o compiled_file newfile.ml

you can submit newfile.ml

or to compile locally all at once:

ocamlopt -pp camlp4o -o compiled_file file.ml

7 years later

In your case, isn't it possible to do the preprocessing on your machine and submit the preprocessed version to SPOJ?