喜欢用ocaml的小朋友们注意了
查看原帖
喜欢用ocaml的小朋友们注意了
1499825
MizuhasiParsee楼主2024/10/20 19:27

这题的行末可能是 "\r\n",所以用 Scanf.scanf 是会 RE 的。 保守点,还是得

read_line ()
|> String.trim
|> String.split_on_char ' '
|> List.map int_of_string

这样来读入一整行的数。

同时,一旦使用 read_line,就只能使用 read_ 开头的读入函数。所以前面两个维数也得这样读。

不在乎 warning 的可以直接:

let [rows; cols] = read_line ()
	|> String.trim
	|> String.split_on_char ' '
	|> List.map int_of_string
;;

对于转置输出,既然你是来玩 ocaml 的,那就别写循环,要记住 ocaml 是有 Seq.transpose 的。

2024/10/20 19:27
加载中...