You are viewing a single comment's thread. Return to all comments →
Not really good answer... but I just want to share my answer
import qualified Data.Set as Set getMultipleLines :: Int -> IO [String] getMultipleLines n | n <= 0 = return [] | otherwise = do x <- getLine xs <- getMultipleLines (n - 1) return (x:xs) duplicateExist [] = False duplicateExist (x:xs) = if elem x xs then True else duplicateExist xs solve 0 = return () solve n = do x <- getMultipleLines =<< read <$> getLine let s = Set.toAscList . Set.fromList $ map (\y -> map (read :: String -> Int) $ words y) x putStrLn $ if duplicateExist $ map (\y -> y !! 0) s then "NO" else "YES" solve (n - 1) main = do n <- read <$> getLine :: IO Int solve n
Seems like cookies are disabled on this browser, please enable them to open this website
Functions or Not?
You are viewing a single comment's thread. Return to all comments →
Not really good answer... but I just want to share my answer