結果

問題 No.708 (+ー)の式
ユーザー ducktailducktail
提出日時 2018-09-02 13:09:09
言語 Haskell
(9.8.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 647 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 142,700 KB
最終ジャッジ日時 2023-10-25 06:36:54
合計ジャッジ時間 797 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

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

Main.hs:4:1: error:
    Could not load module ‘Text.Parsec’
    It is a member of the hidden package ‘parsec-3.1.16.1’.
    You can run ‘:set -package parsec’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import Text.Parsec (parse, char, digit)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:5:1: error:
    Could not load module ‘Text.Parsec’
    It is a member of the hidden package ‘parsec-3.1.16.1’.
    You can run ‘:set -package parsec’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
5 | import qualified Text.Parsec as P
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:6:1: error:
    Could not load module ‘Text.Parsec.String’
    It is a member of the hidden package ‘parsec-3.1.16.1’.
    You can run ‘:set -package parsec’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
6 | import Text.Parsec.String
  | ^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #

import Control.Applicative
import Data.List
import Data.Char (digitToInt)
import Text.Parsec (parse, char, digit)
import qualified Text.Parsec as P
import Text.Parsec.String

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

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

num :: Parser Int
num = do
  f <- negate <$ char '-' <|> return id
  n <- digitToInt <$> digit
  return $ f n

term :: Parser Int
term = char '(' *> expr <* char ')' <|> num

expr :: Parser Int
expr = do
  x <- term
  fs <- P.many $ do
    f <- (+) <$ char '+' <|> (-) <$ char '-'
    x <- term
    return $ flip f x
  return $ foldl' (\x f -> f x) x fs
0