結果
| 問題 | No.222 引き算と足し算 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-05-14 00:59:14 |
| 言語 | Standard ML (MLton 20241230) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 873 bytes |
| 記録 | |
| コンパイル時間 | 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)
ソースコード
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