Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Applicative
  2. import Control.Monad
  3. import System.IO
  4. import qualified Data.Vector as V
  5. import qualified Data.Text as T
  6. import Data.Char (isUpper, isLower, toUpper)
  7.  
  8. check :: String -> String -> Bool
  9. check _a _b = check' (T.length a) (T.length b)
  10.    where
  11.    a = T.pack _a
  12.    b = T.pack _b
  13.    a_ i = T.index a (i - 1) -- "If we use <i> characters, what is the last character?"
  14.    b_ i = T.index b (i - 1)
  15.    checks = V.generate (T.length a + 1) (\i ->
  16.             V.generate (T.length b + 1) (\j ->
  17.             check' i j))
  18.     checks_ i j
  19.         | i < 0 || j < 0 = False
  20.         | otherwise = checks V.! i V.! j
  21.     check' 0 0 = True
  22.    check' 0 n = False
  23.     check' m 0 = isLower (a_ m) && checks_ (m - 1) 0
  24.    check' m n
  25.         | isUpper (a_ m) = (a_ m) == (b_ n) && checks_ (m - 1) (n - 1) -- Must use both
  26.         | otherwise = (toUpper (a_ m) == (b_ n) && checks_ (m - 1) (n - 1)) -- Use this letter
  27.                    || checks_ (m - 1) n -- Skip this letter
  28.  
  29.  
  30. main :: IO ()
  31. main = do
  32.     q_temp <- getLine
  33.     let q = read q_temp :: Int
  34.     forM_ [1..q] $ \a0  -> do
  35.         a <- getLine
  36.         b <- getLine
  37.         putStrLn $ if check a b then "YES" else "NO"
  38.  
  39. getMultipleLines :: Int -> IO [String]
  40.  
  41. getMultipleLines n
  42.     | n <= 0 = return []
  43.     | otherwise = do          
  44.         x <- getLine        
  45.         xs <- getMultipleLines (n-1)    
  46.         let ret = (x:xs)    
  47.         return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement