結果
| 問題 |
No.708 (+ー)の式
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-02 13:09:09 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 647 bytes |
| コンパイル時間 | 196 ms |
| コンパイル使用メモリ | 148,608 KB |
| 最終ジャッジ日時 | 2024-11-14 20:35:59 |
| 合計ジャッジ時間 | 694 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、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:4: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.
|
4 | import Text.Parsec (parse, char, digit)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Main.hs:5: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.
|
5 | import qualified Text.Parsec as P
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Main.hs:6: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.
|
6 | import Text.Parsec.String
| ^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
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