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
- [n] <- liftM (map readInt . B.words) B.getLine
- lst <- liftM (map readInt . take n . B.words) B.getLine :: IO [Int]
- let res = remove_val_index_match lst (n - 1)
- putStrLn "Input: "
- print lst
- putStrLn "Result: "
- print res
- erase idx xs = lft ++ rgt
- where (lft, (_:rgt)) = splitAt idx xs
- remove_val_index_match [] k = []
- remove_val_index_match lst k | k <= -1 = lst
- | (lst!!k) == k = remove_val_index_match (erase k lst) (k - 1)
- | otherwise = remove_val_index_match lst (k - 1)
- -- 6
- -- 0 4 2 3 5 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement