さらにかいりょーばん
module Main () where import Data.Char main = do cs ← getLine let values = map strToInt ( splitBySpace cs ) w = values !! 0 h = values !! 1 print $ area w h print $ around w h strToInt :: String → Int strToInt = read area :: Int → Int → Int area w h = w * h around :: Int → Int → Int around w h = 2*w + 2*h splitBy :: (a→ Bool)→ [a]→ [[a]] splitBy p [] = [] splitBy p xs = a : (splitBy p $ dropWhile p $ b ) where (a,b) = break p xs splitBySpace :: String → [String] splitBySpace = splitBy isSpace
こちらのリンク先を参考に空白区切に対応しますた。ありがとーございます。
感謝感謝。
http://d.hatena.ne.jp/takatoh/20070123/split
空白区切も楽じゃねぇ。
いや、正規表現を使った方法でもっと楽な方法なのも紹介されてますけど。
勉強になりそうな方で。
これだけで読むのにだいぶ時間かかった。
リストへのアクセスに!!演算子が新鮮というかなんというか、妙な気分。