fork(1) download
  1. import Data.List
  2. import Data.Function
  3.  
  4. main = fmap lines getContents >>= \[predmeti,birki] -> let
  5. (predmeti',birki') = unzip $ head $ soljushen sgruppirovaniePredmeti birki
  6. sgruppirovaniePredmeti = groupBy ((==) `on` sort) $ sortBy (compare `on` sort) $ words predmeti
  7. in mapM_ (putStrLn . unwords) [predmeti',birki']
  8.  
  9. soljushen _ [] = [[]]
  10. soljushen gruppi birki = [(birka,predmet):solushn |
  11. (levo,(predmet:gruppa):pravo) <- zip (inits gruppi) (tails gruppi),
  12. let birka = zipWith const birki predmet,
  13. sort predmet == sort birka,
  14. solushn <- soljushen (levo++gruppa:pravo) (birki\\birka)]
Success #stdin #stdout 0s 6252KB
stdin
abcabc abc bc abc abcabc abc bc abc abcabc abc bc abc abcabc abc bc abc abcabc abc bc abc
abcabcabcbcabcabcabcabcbcabcabcabcabcbcabcabcabcabcbcabcabcabcabcbcabc
stdout
abcabc abcbca bcabca bca bc bcabca bcabca bc bca bca bca bca bc bca bca bca bca bc bca bc
abcabc abcabc abcabc abc bc abcabc abcabc bc abc abc abc abc bc abc abc abc abc bc abc bc