如何在OCaml中使用scanf

时间:2016-05-03 16:10:50

标签: ocaml scanf

我正在尝试制作以下内容:

x = scanf(stdin);

但它必须在OCaml,我一直在阅读,但我似乎无法找到一个正确的方法来做到这一点,我正在做的是一个纸牌游戏,并在一开始我想问用户游戏,通过终端,将要玩的玩家数量,这就是我需要从标准扫描的原因。非常感谢你提前。

2 个答案:

答案 0 :(得分:0)

对于这么简单的任务,scanf可能有点过分。您可能希望使用read_int开始使用。

# read_int ();;
17
- : int = 17

(这里的第二行是用户输入的,即我。)

答案 1 :(得分:0)

您不必指定const rowData = [ { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 09:00:00", dateEnd: "2019-10-12 09:05:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 08:40:00", dateEnd: "2019-10-12 08:45:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 08:15:00", dateEnd: "2019-10-12 08:25:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 08:10:00", dateEnd: "2019-10-12 08:15:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 08:00:00", dateEnd: "2019-10-12 08:05:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 07:00:00", dateEnd: "2019-10-12 08:05:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 06:00:00", dateEnd: "2019-10-12 07:05:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 05:00:00", dateEnd: "2019-10-12 06:05:000" }, { server: "Server 1", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 04:00:00", dateEnd: "2019-10-12 05:05:000" }, { server: "Server 2", ping: "10 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 09:03:00", dateEnd: "2019-10-12 09:05:000" }, { server: "Server 2", ping: "2 ms", dl: "50Mbit/s", ul: "50Mbit/s", ispcon: true, dateStart: "2019-10-12 09:00:00", dateEnd: "2019-10-12 09:01:000" } ]; const res = Object.values( rowData.sort((a, b) => (new Date(a.dateStart).getTime()) - (new Date(b.dateStart).getTime())).reduce((acc, curr) => { const { server, ...rest_curr } = curr; return { ...acc, [curr.server]: curr.server in acc ? { ...acc[curr.server], data: [...acc[curr.server].data, { ...rest_curr }] } : { ...curr, data: [{ ...rest_curr }] } }; }, {}) ); console.log(res);,可以执行以下操作:

stdin