Advertisement
osipyonok

Huiaskel 1-7

Jan 22nd, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Monad
  2. import qualified Data.ByteString.Char8 as B
  3. import Data.Maybe
  4. import Data.List
  5. import Control.Arrow
  6.  
  7.  
  8. readInt :: B.ByteString -> Int
  9. readInt = fst . fromJust . B.readInt
  10.  
  11. main :: IO ()
  12. main = do
  13.   [lng] <- liftM (map readInt . B.words) B.getLine
  14.   lst   <- liftM (map readInt . take lng . B.words) B.getLine :: IO [Int]
  15.   [n]   <- liftM (map readInt . B.words) B.getLine
  16.  
  17.   putStrLn "Input: "
  18.   print lst
  19.   print n
  20.   putStrLn "Result: "
  21.   let res = solve lst n
  22.   print res
  23.  
  24.  
  25. comp (a1,b1) (a2,b2) | b1 < b2    = LT
  26.                      | otherwise  = GT
  27.  
  28.  
  29. finalize []    = []
  30. finalize (h:t) = [(fst h)] ++ (finalize t)
  31.  
  32.  
  33. solve lst n = finalize good
  34.     where good = sortBy comp (take n (reverse (sort (zip lst [0..]))))
  35.  
  36. -- 7
  37. -- 1 5 3 7 6 2 9
  38. -- 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement