Дан целочисленный массив из n элементов. Элементы массива могут принимать целые значения от 1 до 10000 включительно. Напишите программу, позволяющую найти и вывести минимальный элементов массива, шестнадцатеричная запись которого содержит ровно две цифры, причём первая (старшая) цифра больше второй (младшей). Если таких чисел нет, нужно вывести ответ 0.
Так как целевой ЯП не указан, приведу пример на Haskell.
Точка входа - функция main.
Main.hsmodule Main whereimport ArrsMinmain :: IO ()main = dialogArrsMin.hsmodule ArrsMin whereimport System.IO(hFlush, stdout)import Data.Char(isDigit)import Data.Maybe(isJust)import Control.Applicativeimport Numeric(showHex)import MyParserLibparserInt :: Parser IntparserInt = Parser (\s -> let res = unParser (some digitParser) s in case res of [] -> [] ((i, rest) : _) -> [(read i :: Int, rest)] ) where digitParser = predP isDigitparserIntSequence :: Parser [Int]parserIntSequence = Parser (\s -> let res = unParser (some elementParser) s in case res of [] -> [] ((i, rest) : _) -> [(i, rest)] ) where elementParser = (<*) parserInt $ many $ charP ' 'intToHex :: Int -> StringintToHex = flip showHex ""isItCorrect :: String -> BoolisItCorrect s | (length s == 2) && (head s > s !! 1) = True | otherwise = FalsetakeOnlyCorrect :: Maybe [Int] -> Maybe [Int]takeOnlyCorrect = fmap $ filter (isItCorrect . intToHex)minimum' :: (Ord a) => Maybe [a] -> Maybe aminimum' Nothing = Nothingminimum' (Just []) = Nothingminimum' (Just a) = Just (minimum a)unJust :: Maybe a -> IO aunJust (Just a) = return aunJust Nothing = fail "You can't unjust Nothing"dialog :: IO ()dialog = do putStr "Put your int sequence: " hFlush stdout stupidUserInput <- getLine let sequen = parseString stupidUserInput parserIntSequence let answer = minimum' $ takeOnlyCorrect sequen if isJust answer then do number <- unJust answer print number else putStrLn "0"MyParserLibmodule MyParserLib whereimport Data.Listimport Control.Applicativetype DataText = Stringtype RestText = Stringtype PResults parsedType = [(parsedType, RestText)]newtype Parser parsedType = Parser {unParser :: DataText -> PResults parsedType}instance Functor Parser where fmap f (Parser p1) = Parser p2 where p2 s = convert (p1 s) convert = map (\(val, s) -> (f val, s))instance Applicative Parser where pure x = Parser (\str -> [(x, str)]) pf <*> px = Parser (\str -> [(f x, sx) | (f, sf) <- unParser pf str, (x, sx) <- unParser px sf])instance Alternative Parser where empty = Parser (const []) px <|> py = Parser (\s -> unParser px s ++ unParser py s)parseString :: String -> Parser a -> Maybe aparseString str (Parser p) = case p str of [(val, "")] -> Just val _ -> NothingpredP :: (Char -> Bool) -> Parser CharpredP p = Parser f where f "" = [] f (c:cs) | p c = [(c, cs)] | otherwise = []charP :: Char -> Parser CharcharP ch = predP (\c -> c == ch)stringP :: String -> Parser StringstringP str = Parser f where f str' | str == str' = [("", str)] | otherwise = [] skip :: (Char -> Bool) -> Parser ()skip p = Parser (\str -> [((), dropWhile p str)])prefixP :: String -> Parser StringprefixP token = Parser f where f str | token `isPrefixOf` str = [(drop (length token) str, token)] | otherwise = []skipString :: String -> Parser ()skipString token = () <$ prefixP token