結果
| 問題 |
No.369 足し間違い
|
| コンテスト | |
| ユーザー |
alpha_virginis
|
| 提出日時 | 2016-05-13 22:28:36 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 808 bytes |
| コンパイル時間 | 3,605 ms |
| コンパイル使用メモリ | 180,836 KB |
| 実行使用メモリ | 6,656 KB |
| 最終ジャッジ日時 | 2024-10-05 16:51:29 |
| 合計ジャッジ時間 | 4,051 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.Array.IO
main :: IO ()
main = do
s1 <- C.getLine
let (n,r1) = nextInt s1
s2 <- C.getLine
let a = solve s2
s3 <- C.getLine
let (b,r2) = nextInt s3
print $ a - b
solve :: C.ByteString -> Int
solve ss
| C.null ss = 0
| otherwise = x + solve rs
where (x,rs) = nextInt ss
nextInt :: C.ByteString -> (Int, C.ByteString)
nextInt ss
| isDigit x || x == '-' = nextInt2 0 ss
| otherwise = nextInt $ C.tail ss
where x = C.head ss
nextInt2 :: Int -> C.ByteString -> (Int, C.ByteString)
nextInt2 n ss
| C.null ss = (n, ss)
| y == '-' = (-z,zs)
| isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys
| otherwise = (n, ys)
where y = C.head ss
ys = C.tail ss
(z,zs) = nextInt2 0 ys
alpha_virginis