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