結果

問題 No.222 引き算と足し算
ユーザー ducktailducktail
提出日時 2018-05-10 15:10:08
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 538 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 151,640 KB
最終ジャッジ日時 2024-04-27 02:32:57
合計ジャッジ時間 632 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )

Main.hs:2:1: error: [GHC-87110]
    Could not load module ‘Text.Parsec’.
    It is a member of the hidden package ‘parsec-3.1.17.0’.
    Use -v to see a list of the files searched for.
  |
2 | import Text.Parsec
  | ^^^^^^^^^^^^^^^^^^

Main.hs:3:1: error: [GHC-87110]
    Could not load module ‘Text.Parsec.String’.
    It is a member of the hidden package ‘parsec-3.1.17.0’.
    Use -v to see a list of the files searched for.
  |
3 | import Text.Parsec.String (Parser)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Control.Applicative ((<$>), (*>))
import Text.Parsec
import Text.Parsec.String (Parser)

main :: IO ()
main = solve <$> getLine >>= print

solve :: String -> Int
solve = either (const 0) id . parse expr ""

num :: Parser Int
num = do
  f <- (char '+' *> return id) <|> (char '-' *> return negate) <|> return id
  d <- many1 digit >>= return . read
  return $ f d

op :: Parser (Int -> Int -> Int)
op = char '+' *> return (-) <|> char '-' *> return (+)

expr :: Parser Int
expr = do
  x <- num
  f <- op
  y <- num
  return $ f x y
0