結果

問題 No.423 ハムスター語初級(数詞)
ユーザー NaruYNaruY
提出日時 2018-02-15 22:02:17
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 880 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 163,440 KB
実行使用メモリ 7,192 KB
最終ジャッジ日時 2023-08-28 14:35:03
合計ジャッジ時間 1,539 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,032 KB
testcase_01 AC 2 ms
7,048 KB
testcase_02 AC 2 ms
7,056 KB
testcase_03 AC 2 ms
7,136 KB
testcase_04 AC 2 ms
7,116 KB
testcase_05 AC 3 ms
7,092 KB
testcase_06 AC 2 ms
7,068 KB
testcase_07 AC 2 ms
7,192 KB
testcase_08 AC 3 ms
7,088 KB
testcase_09 AC 2 ms
7,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
strToInt s = (read :: String -> Int) s
b2i xs = foldl (\x y -> 2 * x + y) 0 $ map (\x -> read [x]) xs
i2b = concat . (map show) . reverse . i2b' where i2b' 0 = []; i2b' n = mod n 2 : i2b' (div n 2)

main = do
    ham <- getLine
    let answ1 = show $ i2b $ 2 * (b2i $ conv ham)
    let answ2 = foldr (++) [] (map ans answ1)
    if answ2 == [] then putStrLn $ "ham"
                   else putStrLn $ answ2
    
ans :: Char -> String
ans '0' = "ham"
ans '1' = "hamu"
ans _ = ""

conv :: String -> String
conv [] = []
conv ham = if (length ham) <= 3
           then "0"
           else if (take 4 ham) == "hamu"
                then "1" ++ conv (drop 4 ham)
                else "0" ++ conv (drop 3 ham)
0