Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Applicative
- import Control.Monad
- import System.IO
- import qualified Data.Vector as V
- import qualified Data.Text as T
- import Data.Char (isUpper, isLower, toUpper)
- check :: String -> String -> Bool
- check _a _b = check' (T.length a) (T.length b)
- where
- a = T.pack _a
- b = T.pack _b
- a_ i = T.index a (i - 1) -- "If we use <i> characters, what is the last character?"
- b_ i = T.index b (i - 1)
- checks = V.generate (T.length a + 1) (\i ->
- V.generate (T.length b + 1) (\j ->
- check' i j))
- checks_ i j
- | i < 0 || j < 0 = False
- | otherwise = checks V.! i V.! j
- check' 0 0 = True
- check' 0 n = False
- check' m 0 = isLower (a_ m) && checks_ (m - 1) 0
- check' m n
- | isUpper (a_ m) = (a_ m) == (b_ n) && checks_ (m - 1) (n - 1) -- Must use both
- | otherwise = (toUpper (a_ m) == (b_ n) && checks_ (m - 1) (n - 1)) -- Use this letter
- || checks_ (m - 1) n -- Skip this letter
- main :: IO ()
- main = do
- q_temp <- getLine
- let q = read q_temp :: Int
- forM_ [1..q] $ \a0 -> do
- a <- getLine
- b <- getLine
- putStrLn $ if check a b then "YES" else "NO"
- getMultipleLines :: Int -> IO [String]
- getMultipleLines n
- | n <= 0 = return []
- | otherwise = do
- x <- getLine
- xs <- getMultipleLines (n-1)
- let ret = (x:xs)
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement