2016-01-03 02:42:02 +01:00
|
|
|
transpose:: [[a]] -> [[a]]
|
|
|
|
transpose ([]:xs) = []
|
|
|
|
transpose x = (map head x) : transpose (map tail x)
|
|
|
|
|
|
|
|
addEmpty :: Int -> [a] -> [a] -> [a]
|
|
|
|
addEmpty x v y
|
2016-01-04 13:41:30 +01:00
|
|
|
| ysize == x = y
|
|
|
|
| ysize < x = addEmpty x v (y ++ v)
|
2016-01-03 02:42:02 +01:00
|
|
|
| otherwise = []
|
|
|
|
where ysize = length y
|
|
|
|
|
|
|
|
formatLine :: [String] -> [String]
|
|
|
|
formatLine x = map (addEmpty nb " ") x
|
|
|
|
where nb = maximum $ map length x
|
|
|
|
|
|
|
|
formatLines :: [[String]] -> [[String]]
|
|
|
|
formatLines x = map formatLine x
|
|
|
|
|
|
|
|
completeMatrix :: [[String]] -> [[String]]
|
|
|
|
completeMatrix m = map (addEmpty nb [""]) m
|
|
|
|
where nb = maximum $ map length m
|
|
|
|
|
|
|
|
column :: [[String]] -> [[String]]
|
|
|
|
column x = transpose $ formatLines $ transpose $ completeMatrix x
|
|
|
|
|
|
|
|
main = do
|
|
|
|
content <- getContents
|
2016-01-04 13:41:30 +01:00
|
|
|
putStr $ unlines $ map unwords $ column $ map words $ lines content
|