結果

問題 No.49 算数の宿題
コンテスト
ユーザー tanson
提出日時 2026-04-13 05:22:28
言語 Standard ML
(MLton 20241230)
コンパイル:
mlton_wrapper _filename_
実行:
./main
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,183 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,680 ms
コンパイル使用メモリ 704,744 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-13 05:22:34
合計ジャッジ時間 3,615 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

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


exception BadInput
fun findAns s =
    let
        fun chars2Int [] acc = (acc, [])
          | chars2Int (h::tl) acc =
            if h = #"*" orelse h = #"+"
            then (acc, h::tl)
            else chars2Int tl (acc * 10 + (Char.ord h - Char.ord #"0"))

        fun findAnsAux [] acc = acc
          | findAnsAux (operatorCh :: l) acc =
            let
                val (operand, rest) = chars2Int (List.tl l) (Char.ord (List.hd l) - Char.ord #"0")
            in
                if operatorCh = #"*"
                then findAnsAux rest (acc + operand)
                else findAnsAux rest (acc * operand)
            end
                
        val ch_s = String.explode s
        val (firstVal, restChs) = chars2Int (List.tl ch_s) (Char.ord (List.hd ch_s) - Char.ord #"0")
    in
        findAnsAux restChs firstVal
    end


val () =
    let
        val s = readStr ()

        val ans = findAns s
    in
        print (Int.toString ans ^ "\n")
    end

0