fork(3) download
  1. -- ******************************************************************************************
  2. -- * POH6+ (パイザ オンライン ハッカソン) *
  3. -- * 単語リストの単語を用いて作ることができる最長の回文のうち辞書順(昇順)最小の回文を求める *
  4. -- ******************************************************************************************
  5.  
  6. import Data.List (delete,sort)
  7.  
  8. solve = build "" ""
  9. build r c [] = reverse r ++ c ++ r
  10. build r c (w:ws)
  11. | reverse w `elem` ws = build (reverse w++r) c next
  12. | w == reverse w && null c = build r w ws
  13. | otherwise = build r c ws
  14. where next = delete (reverse w) ws
  15.  
  16. main = interact $ solve . sort . tail . lines
  17.  
Success #stdin #stdout 0s 8388607KB
stdin
6
fdk
jnv
vnj
kdf
qaq
bhh
stdout
fdkjnvqaqvnjkdf