fork download
  1. starts :: String -> String -> Bool
  2.  
  3. starts first second =
  4. if length second > length first
  5. then False
  6. else if (take (length second) first) == second
  7. then True
  8. else False
  9.  
  10. ends :: String -> String -> Bool
  11. ends first second = starts (reverse first) (reverse second)
  12.  
  13.  
  14.  
  15. add_plural :: String -> String
  16. add_plural word
  17. | ends word "ch" = word ++ "es"
  18. | ends word "x" = word ++ "es"
  19. | ends word "s" = word ++ "es"
  20. | ends word "o" = word ++ "es"
  21. | ends word "f" = (take (length word-1) word) ++ "ves"
  22. | ends word "fe" = (take (length word-2) word) ++ "ves"
  23. | ends word "y" = (take (length word-1) word) ++ "ies"
  24. | otherwise = word ++ "s"
  25.  
  26. run_test :: Int -> IO()
  27.  
  28. run_test 0 = do
  29.  
  30. run_test n = do
  31. word <- getLine
  32. putStrLn (add_plural word)
  33. run_test (n-1)
  34.  
  35.  
  36. main = do
  37. readLn >>= run_test
  38.  
Success #stdin #stdout 0s 6296KB
stdin
3
contest
hero
lady
stdout
contests
heroes
ladies