Created
October 18, 2014 10:56
-
-
Save l4u/1107d08cd38e6cfd0fa7 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
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