Advertisement
osipyonok

Huiaskel 1-17

Jan 22nd, 2019
194
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. readInt :: B.ByteString -> Int
  8. readInt = fst . fromJust . B.readInt
  9.  
  10. main :: IO ()
  11. main = do
  12.   [n] <- liftM (map readInt . B.words) B.getLine
  13.   lst <- liftM (map readInt . take n . B.words) B.getLine :: IO [Int]
  14.   let res = remove_val_index_match lst (n - 1)
  15.   putStrLn "Input: "
  16.   print lst
  17.   putStrLn "Result: "
  18.   print res
  19.  
  20.  
  21. erase idx xs = lft ++ rgt
  22.   where (lft, (_:rgt)) = splitAt idx xs
  23.  
  24.  
  25. remove_val_index_match []  k = []
  26. remove_val_index_match lst k | k <= -1        = lst
  27.                              | (lst!!k) ==  k = remove_val_index_match (erase k lst) (k - 1)
  28.                              | otherwise      = remove_val_index_match lst (k - 1)
  29.  
  30. -- 6
  31. -- 0 4 2 3 5 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement