結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-04-09 02:04:50 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 819 bytes |
| コンパイル時間 | 10,691 ms |
| コンパイル使用メモリ | 170,368 KB |
| 実行使用メモリ | 5,760 KB |
| 最終ジャッジ日時 | 2024-07-22 16:49:40 |
| 合計ジャッジ時間 | 9,420 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
コンパイルメッセージ
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:15:7: warning: [GHC-63394] [-Wx-partial]
In the use of ‘head’
(imported from Prelude, but defined in GHC.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty."
|
15 | | head a /= '-' = (read a, readPoint b)
| ^^^^
[2 of 2] Linking a.out
ソースコード
import Data.List.Split
main :: IO ()
main = do
getLine
a <- map parse . lines <$> getContents
let (i, p) = (sum $ map fst a, sum $ map snd a)
putStrLn $ showWithPoint(10^10 * i + p)
parse :: String -> (Integer, Integer)
parse = zipInt . splitWhen (== '.')
zipInt :: [String] -> (Integer, Integer)
zipInt [a, b]
| head a /= '-' = (read a, readPoint b)
| otherwise = (read a, -readPoint b)
zipInt [a] = (read a, 0)
readPoint :: String -> Integer
readPoint = read . take 10 . (++ repeat '0')
showWithPoint :: Integer -> String
showWithPoint x
| x < 0 = '-':showWithPoint (-x)
| otherwise = (show (x `div` 10 ^ 10)) ++ "." ++ (show10 10 (x `mod` 10^10))
show10 :: Integer -> Integer -> String
show10 0 _ = ""
show10 d x = (show $ x `div` 10^(d-1)) ++ show10 (d - 1) (x `mod` 10^(d-1))
trineutron