結果

問題 No.455 冬の大三角
ユーザー ducktailducktail
提出日時 2017-09-09 15:44:57
言語 OCaml
(5.1.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 809 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 16,768 KB
最終ジャッジ日時 2024-04-27 02:29:45
合計ジャッジ時間 752 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
File "Main.ml", line 14, characters 30-42:
14 |                if i = x then (s.[y] <- '*'; printf "%s\n" s)
                                   ^^^^^^^^^^^^
Error: Syntax error: strings are immutable, there is no assignment syntax for them.
Hint: Mutable sequences of bytes are available in the Bytes module.
Hint: Did you mean to use 'Bytes.set'?

ソースコード

diff #

open Printf
open Scanf

let find ar h w =
  let rec iter i j ps = 
    if i = h then ps
    else if j = w then iter (i+1) 0 ps
    else if ar.(i).[j] = '*' then iter i (j+1) ((i,j) :: ps)
    else iter i (j+1) ps in
  iter 0 0 []
       
let print_tbl ar w x y =
  Array.iteri (fun i s ->
               if i = x then (s.[y] <- '*'; printf "%s\n" s)
               else printf "%s\n" s) ar

let () =
  let h, w = scanf "%d %d " (fun x y -> (x, y)) in
  let tbl = Array.init h (fun _ -> let s = scanf "%s " (fun x -> x) in s) in
  match find tbl h w with
    (x1, y1) :: (x2, y2) :: _ -> begin
      let rec loop i j =
        if j = w then loop (i+1) 0
        else if (x1-i) * (y2-j) - (y1-j) * (x2-i) = 0 then loop i (j+1)
        else print_tbl tbl w i j in
      loop 0 0
    end
  | _ -> failwith "find"
0