Haskell, (削除) 127 (削除ここまで) 120 bytes
e=[]:e
i#[x]=[]
i#s|t<-foldl(flip$zipWith(:))e$init s,j<-i++last s=(map((j>>" ")++)(init t)++[j++last t]):j#t
f s=s:""#s
Input is a list of lines, e.g. ["DC","AB"] for the second test case, output is a list of lists of lines: [["DC","AB"],[" D","ABC"],["ABCD"]]. Use mapM (putStrLn . unlines) to pretty-print the result.
Edit: Saved 7 bytes by noticing that the shorter transpose I found some while a go comes in handy because it can be modified to reverse each transposed directly.
Haskell: https://www.haskell.org/
Laikoni
- 26.4k
- 7
- 54
- 116