結果
問題 |
No.423 ハムスター語初級(数詞)
|
ユーザー |
![]() |
提出日時 | 2016-10-23 21:42:08 |
言語 | Haskell (9.10.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 646 bytes |
コンパイル時間 | 4,563 ms |
コンパイル使用メモリ | 169,600 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 02:07:07 |
合計ジャッジ時間 | 5,079 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 WA * 1 |
コンパイルメッセージ
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
ソースコード
module Main where import Control.Applicative import Data.Char main :: IO () main = putStrLn =<< toHam . toStr. (*2) . toNum . toNumStr <$> getLine toNumStr :: String -> String toNumStr [] = [] toNumStr xs = if length xs >= 4 && take 4 xs == "hamu" then '1' : toNumStr (drop 4 xs) else '0' : toNumStr (drop 3 xs) toNum :: String -> Int toNum = foldl (\sum x -> sum * 2 + digitToInt x) 0 toStr :: Int -> String toStr = dropWhile (=='0') . reverse . rec where rec 0 = [] rec n = intToDigit (n `mod` 2) : rec (n `div` 2) toHam :: String -> String toHam = foldr (\x y -> (if x == '1' then "hamu" else "ham") ++ y) []