Skip to content

Instantly share code, notes, and snippets.

@gorlum0
Created August 18, 2011 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gorlum0/1153330 to your computer and use it in GitHub Desktop.
Save gorlum0/1153330 to your computer and use it in GitHub Desktop.
codeforces - 37 - A (hs)
{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-}
{-# LANGUAGE BangPatterns #-}
{-(c) gorlum0 [at] gmail.com-}
import Text.Printf
import Data.List (group, sort, maximumBy)
import Data.Ord (comparing)
towers bs = (h, t)
where
bs' = group . sort $ bs
h = length $ maximumBy (comparing length) bs'
t = length bs'
body [] = []
body (n:xs) = towers bs : body xs'
where
n' = read n
(bs, xs') = splitAt n' xs
fmt :: (Int, Int) -> String
fmt (h, t) = printf "%d %d" h t
main = do
ws <- words `fmap` getContents
mapM_ (putStrLn . fmt) (body ws)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment