Guest User

Untitled

a guest
Jun 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. uis_tsai@tw-louistsai2:~
  2. import Data.Function ((&))
  3. import Data.Map (Map)
  4. import qualified Data.Map as Map
  5. import System.IO
  6. import Control.Monad
  7.  
  8.  
  9. testOnePair :: (Ord k, Eq a) => (k, a) -> Map k a -> (Bool, Map k a)
  10. testOnePair (k,v) table =
  11. case (Map.lookup k table)
  12. of Nothing -> (True, Map.insert k v table)
  13. Just v'-> if (v == v') then (True, table)
  14. else (False, table)
  15.  
  16.  
  17. testFunction [] table = True
  18. testFunction ((k,v):lst) table =
  19. case testOnePair (k,v) table
  20. of (False, _) -> False
  21. (True, table') -> testFunction lst table'
  22.  
  23.  
  24.  
  25. _main = do
  26. nLine <- readLn :: IO Int
  27. replicateM_ nLine $ return ()
  28.  
  29. main = do
  30. nTestCase <- readLn :: IO Int
  31. replicateM_ nTestCase _main
  32. --forM_ [1..nTestCase] $ \_ -> _main
  33.  
  34.  
  35. --print $ show (nTestCase :: Int)
  36. ~
Add Comment
Please, Sign In to add comment