Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created March 29, 2011 11:51
Show Gist options
  • Select an option

  • Save oskimura/892214 to your computer and use it in GitHub Desktop.

Select an option

Save oskimura/892214 to your computer and use it in GitHub Desktop.
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