0
0

More than 5 years have passed since last update.

# バス代(2013.4.6の過去問)

Last updated at Posted at 2013-12-19

``````module Doukaku.Bus (solve) where
import Data.List (sort)
import Data.List.Split (splitOn)

roundup :: Int -> Int
roundup n = ((n + 9) `div` 10) * 10

solve :: String -> String
solve input = show \$ adultsFee + childrenFee + infantsFee
where
(base', _:people') = break (== ':') input
people = splitOn "," people'
children = filter ((== 'C') . head) people
infants' = filter ((== 'I') . head) people
infants = drop (length adults * 2) . map snd . reverse . sort .
zip (map (flip rate 100) infants') \$ infants'
adultsFee = sum . map (roundup . flip rate base) \$ adults
childrenFee = sum . map (roundup . (`div` 2) . flip rate base) \$ children
infantsFee = sum . map (roundup . (`div` 2) . flip rate base) \$ infants

rate :: String -> (Int -> Int)
rate (_:'n':_) = id
rate (_:'p':_) = const 0
rate (_:'w':_) = (`div` 2)
``````

http://qiita.com/Nabetani/items/84255ac417ef25069a3b に他の方の回答もありますので、見ると参考になるでしょう。

0
0
0

Register as a new user and use Qiita more conveniently

1. You get articles that match your needs
2. You can efficiently read back useful information
3. You can use dark theme
What you can do with signing up
0
0