Created
April 4, 2011 05:44
-
-
Save oskimura/901182 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main where | |
| import Control.Applicative | |
| import Data.List | |
| import Text.Printf | |
| import Data.Function (on) | |
| import Data.Maybe | |
| import qualified Data.Tree as T | |
| import qualified Data.Map as M | |
| splitBy :: (a -> Bool) -> [a] -> [[a]] | |
| splitBy p [] = [] | |
| splitBy p xs = a : (splitBy p $ dropWhile p $ b) | |
| where | |
| (a, b) = break p xs | |
| split :: String -> [String] | |
| split = splitBy (=='\\') | |
| buildDir = T.unfoldTree phi | |
| where phi (n,ps) = (delete '\\' n, groupPath $ filter (not . null) ps) | |
| groupPath = map grouping . groupBy (on eqpath head) | |
| grouping ss = (head . head $ ss, map tail ss) | |
| eqpath = on (==) (fst . (break ('\\'==))) | |
| buildTree = map T.flatten . map buildDir . groupPath . map f . map split . sort | |
| where f (x1:x2:xs) = (x1++x2) :xs | |
| maxFileNum = maximum . map length . (map $ filter $ elem '.') . buildTree | |
| maxSubDirNum = maximum . map length . map tail . (map $ filter $ not . elem '.') . buildTree | |
| main :: IO () | |
| main = do { ns <- lines <$> getContents | |
| ; let dirNum = maxSubDirNum ns in | |
| let fileNum = maxFileNum ns in | |
| (printf "%d %d\n" (dirNum) fileNum) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment