Facebook
From Soft Cheetah, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 106
  1. import System.IO
  2. import Control.Monad
  3. import Data.List
  4.  
  5. num :: (Num a) => String -> String -> a
  6. num [] [] = 0
  7. num (x:xs) (y:ys)
  8.     | x == y = 1 + num xs ys
  9.     | otherwise = num xs ys
  10.  
  11. percentage key sub = (num key sub) / (genericLength key)
  12.  
  13. passOrFail :: (Ord a, Fractional a) => a -> String
  14. passOrFail x
  15.     | x < 0.9 = "fail"
  16.     | otherwise = "pass"
  17.  
  18. main :: IO ()
  19. main = do
  20.     key <- getLine
  21.     input_line <- getLine
  22.     let n = read input_line :: Int
  23.    
  24.     replicateM n $ do
  25.       str <- getLine
  26.       let p = passOrFail $ percentage key str
  27.       putStrLn p
  28.       return ()
  29.     return ()