いろんな言語で宿題スレat TECH
いろんな言語で宿題スレ - 暇つぶし2ch300:デフォルトの名無しさん
09/06/26 19:32:49
>>298
-- Haskell

import IO
import Data.Char (isAlpha, toLower)
import Data.Maybe (fromJust)

main = do
fname <- getLine
h <- openFile fname ReadMode
phon <- readPhon h
str <- getLine
putStrLn $ t298 phon str
hClose h

readPhon :: Handle -> IO [(Char,String)]
readPhon h = hGetContents h >>= return . map parse . lines
where
parse :: String -> (Char,String)
parse (c:',':p) = (c,p)

t298 :: [(Char,String)] -> String -> String
t298 phon [] = []
t298 phon (x:xs) | isAlpha x = (fromJust $ lookup (toLower x) phon) ++ ' ' : t298 phon xs
| otherwise = x : t298 phon xs


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch