結果

問題 No.369 足し間違い
ユーザー alpha_virginisalpha_virginis
提出日時 2016-05-13 22:28:36
言語 Haskell
(9.8.2)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 4,773 ms
コンパイル使用メモリ 180,884 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 16:34:09
合計ジャッジ時間 5,394 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 5 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

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
0