• + 1 comment

    import Control.Monad import Data.List (isPrefixOf)

    main :: IO () main = readLn >>= flip replicateM_ testCase

    testCase :: IO () testCase = do _ <- getLine passwords <- fmap words getLine guess <- getLine case sequence (loginAttempt passwords guess) of Nothing -> putStrLn "WRONG PASSWORD" Just xs -> putStrLn $ unwords xs

    loginAttempt :: [String] -> String -> [Maybe String] loginAttempt _ [] = [] loginAttempt passwords guess = case matching of [] -> [Nothing] (x:_) -> Just x : loginAttempt passwords (drop (length x) guess) where matching = filter (flip isPrefixOf guess) passwords