Skip to content

Instantly share code, notes, and snippets.

@l4u
Created October 18, 2014 10:56
Show Gist options
  • Save l4u/1107d08cd38e6cfd0fa7 to your computer and use it in GitHub Desktop.
Save l4u/1107d08cd38e6cfd0fa7 to your computer and use it in GitHub Desktop.
lcs acc (x:xs) (y:ys)
| x == y = lcs (x:acc) xs ys
| otherwise = (reverse acc, x:xs, y:ys)
lcs acc "" y = (reverse acc, "", y)
lcs acc x "" = (reverse acc, x, "")
s l
| length l == 0 = (show 0)
| otherwise = (show $ length l) ++ " " ++ l
main :: IO ()
main = do
x <- getLine :: IO String
y <- getLine :: IO String
let (a, b, c) = lcs "" x y
putStrLn $ s a
putStrLn $ s b
putStrLn $ s c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment