June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -0,0 +1,25 @@
|
|||
module Main where
|
||||
|
||||
import System.Environment
|
||||
|
||||
cmp :: String -> String -> Ordering
|
||||
cmp [] [] = EQ
|
||||
cmp [] (_:_) = LT
|
||||
cmp (_:_) [] = GT
|
||||
cmp (_:xs) (_:ys) = cmp xs ys
|
||||
|
||||
longest :: String -> String
|
||||
longest = longest' "" "" . lines
|
||||
where
|
||||
longest' acc l [] = acc
|
||||
longest' [] l (x:xs) = longest' x x xs
|
||||
longest' acc l (x:xs) = case cmp l x of
|
||||
LT -> longest' x x xs
|
||||
EQ -> longest' (acc ++ '\n':x) l xs
|
||||
GT -> longest' acc l xs
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
(file:_) <- getArgs
|
||||
contents <- readFile file
|
||||
putStrLn $ longest contents
|
||||
Loading…
Add table
Add a link
Reference in a new issue