Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Monad
- import qualified Data.ByteString.Char8 as B
- import Data.Maybe
- import Data.List
- import Control.Arrow
- readInt :: B.ByteString -> Int
- readInt = fst . fromJust . B.readInt
- main :: IO ()
- main = do
- [len] <- liftM (map readInt . B.words) B.getLine
- lst <- liftM (map readInt . take len . B.words) B.getLine :: IO [Int]
- putStrLn "Input: "
- print lst
- putStrLn "Result: "
- print (count_distinct lst)
- count_distinct_impl [] _ ans = ans
- count_distinct_impl (h:t) cur ans | h == cur = count_distinct_impl t h ans
- | otherwise = count_distinct_impl t h (ans + 1)
- count_distinct [] = 0
- count_distinct lst = count_distinct_impl (tail sorted) (head sorted) 1
- where sorted = sort lst
- --5
- --3 -1 2 4 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement