結果

問題 No.222 引き算と足し算
コンテスト
ユーザー tanson
提出日時 2026-05-14 00:59:14
言語 Standard ML
(MLton 20241230)
コンパイル:
mlton_wrapper _filename_
実行:
./main
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 873 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,431 ms
コンパイル使用メモリ 704,860 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-14 00:59:24
合計ジャッジ時間 4,600 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
Warning: main.sml 13.5-16.28.
  Function is not exhaustive.
    missing pattern: (_, nil)
    in: fun findOpIndex i (#"+" :: _) = i  ...  pIndex (i + 1) rest)

ソースコード

diff #
raw source code

fun readStr () =
    let
        fun scan reader stream = SOME (StringCvt.splitl (not o Char.isSpace) reader (StringCvt.skipWS reader stream))
    in
        valOf (TextIO.scanStream scan TextIO.stdIn)
    end

fun intString n =
    if 0 <= n
    then Int.toString n
    else "-" ^ Int.toString (abs n)

fun findOpIndex i (#"+" :: _) = i
  | findOpIndex i (#"-" :: _) = i
  | findOpIndex i (_ :: rest) = 
    findOpIndex (i + 1) rest

val () =
    let
        val s = readStr ()

        val opIndex = findOpIndex 1 (List.tl (String.explode s))

        val x = valOf (Int.fromString (String.substring (s, 0, opIndex)))
        val y = valOf (Int.fromString (String.extract (s, opIndex + 1, NONE)))

        val opChar = String.sub (s, opIndex)

        val ans = if opChar = #"+" then x - y
                  else x + y
    in
        print (intString ans ^ "\n")
    end
0