結果

問題 No.432 占い(Easy)
ユーザー atuk721
提出日時 2017-02-22 06:34:49
言語 Haskell
(9.10.1)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 2,231 ms
コンパイル使用メモリ 176,244 KB
実行使用メモリ 29,056 KB
最終ジャッジ日時 2024-12-30 15:17:56
合計ジャッジ時間 3,613 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:12:11: 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."
   |
12 | proc ss = head . last . take (length ss) $ iterate sub ss
   |           ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import qualified Control.Monad as M
import qualified Data.Char as C

main :: IO ()
main = do
  t <- read <$> getLine
  M.forM_ [1..t] $ \i -> do
    ss <- map C.digitToInt <$> getLine
    print $ proc ss

proc :: [Int] -> Int
proc ss = head . last . take (length ss) $ iterate sub ss

sub :: [Int] -> [Int]
sub [] = []
sub (_:[]) = []
sub (a:b:xs) = result : sub (b:xs)
  where result | a + b < 10 = a + b
               | otherwise  = ((a + b) `div` 10) + ((a + b) `mod` 10)
0