Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Gere Andor
- -- gaim2019
- -- 522/1
- -- Funk2
- import Data.Char
- --import Data.List.Split
- --------------------------------- 1.
- torol_szokoz :: String -> String
- torol_szokoz [] = []
- torol_szokoz (' ':xs) = torol_szokoz(xs)
- torol_szokoz (x:xs) = toLower x:torol_szokoz(xs)
- string_buffer :: Int -> String
- string_buffer 0 = []
- string_buffer n = " " ++ string_buffer (n-1)
- string_negyszog :: Int -> String -> [String]
- string_negyszog n s
- | length s>=n = take n s : string_negyszog n (drop n s)
- | length s>0 = [s ++ string_buffer (n-(length s))]
- | otherwise = []
- string_oszlop :: [String] -> String
- string_oszlop [] = []
- string_oszlop [[]] = []
- string_oszlop [x:xs] = [x] ++ string_oszlop [xs]
- --------------------------------- 2.
- oldPhone_e :: [Char] -> Bool
- oldPhone_e [] = True
- oldPhone_e (s:sz)
- | last (oldPhone [s]) == ('-',0) = False
- | otherwise = oldPhone_e sz
- oldPhone :: Num b => [Char] -> [(Char, b)]
- oldPhone [] = []
- oldPhone (s:sz)
- | isUpper s = ('*',1):(keres b (toLower s)):(oldPhone sz)
- | otherwise = (kc,kn):(oldPhone sz)
- where b=["1","aábc2","deéf3","ghií4","jkl5","mnoóöő6","pqrs7","tuúüűv8","wxyz9","+ 0",".,#","*"]
- (kc,kn) = keres b s
- keres :: Num b => [[Char]] -> Char -> (Char, b)
- keres [] _ = ('-',0) --Nothing (me..)
- keres (x:xs) s
- | (keres_ x s 1) == ('0',0) = keres xs s -- == Nothing (me...0
- | otherwise = (keres_ x s 1)
- keres_ :: Num t => [Char] -> Char -> t -> (Char, t)
- keres_ [] _ _ = ('0',0) -- Nothing (me..)
- keres_ (x:xs) s i
- | x == s && length xs == 0 = (x,i)
- | x == s = ((last xs),i)
- | otherwise = keres_ xs s (i+1)
- keres_ [x] _ i = (x,i) -- Just (x,i)
- --------------------------------- 3.
- valosp :: (Double, Integer)
- valosp = until felt iter (2,1)
- where
- felt (x, hatv) = x/2 == 0
- iter (x, hatv) = (x*(1/2), hatv+1)
- --------------------------------- 4.
- --------------------------------- 5.
- cumul_op :: (a -> a -> a) -> [a] -> [a]
- cumul_op2 :: (a -> a -> a) -> [a] -> [a]
- cumul_op x (fej:l) = fej:cumul_op2 x (fej:l)
- cumul_op2 x (fej:[]) = []
- cumul_op2 x (fej1:fej2:l) = fej:cumul_op2 x (fej:l) where fej=(x fej1 fej2)
- data COMPLEX = Comp {a :: Float, b :: Float}
- instance Show COMPLEX where
- show (Comp a b)
- | b==0 = show a
- | b<0 = show a ++ show b ++ "i"
- | otherwise = show a ++ "+" ++ show b ++ "i"
- --------------------------------- 6.
- data BinFa a =
- Nodus (BinFa a) a (BinFa a)
- | Level
- deriving Show
- --A listából függvény
- beszur :: Ord a => BinFa a -> a -> BinFa a
- beszur Level x = Nodus Level x Level
- beszur (Nodus bal a jobb) x
- | a == x = Nodus bal a jobb
- | a < x = Nodus bal a (beszur jobb x)
- | a > x = Nodus (beszur bal x) a jobb
- --A listából függvény
- listabol :: Ord a => [a] -> BinFa a
- listabol = foldl beszur Level
- --A torol függvény
- torol :: Ord a => BinFa a -> a -> Maybe (BinFa a)
- torol Level x = Nothing
- torol (Nodus bal a jobb) x = case compare x a of
- GT -> case torol jobb x of
- Nothing -> Nothing
- Just binfa -> Just (Nodus bal a binfa)
- LT -> case torol bal x of
- Nothing -> Nothing
- Just binfa -> Just (Nodus binfa a jobb)
- EQ -> torol_ (Nodus bal a jobb) x
- --torol_ Level _ = Nothing
- torol_ :: Ord a => BinFa a -> a -> Maybe (BinFa a)
- torol_ (Nodus Level a Level) x = Just Level
- torol_ (Nodus Level a j) _ = Just j
- torol_ (Nodus b a Level) _ = Just b
- torol_ (Nodus b a j) _ = Just (Nodus b uj jj)
- where uj = mini j
- Just jj = torol j uj
- mini (Nodus Level uj _) = uj
- mini (Nodus b _ _) = mini b
- --------------------------------- 7.
- instance Num COMPLEX where
- (Comp a b) + (Comp c d) = (Comp (a+c) (b+d))
- (Comp a b) - (Comp c d) = (Comp (a-c) (b-d))
- (Comp a b) * (Comp c d) = (Comp (a*c - b*d) (b*d + a*d))
- abs (Comp a b) = Comp (sqrt (a*a + b*b)) 0
- instance Fractional COMPLEX where
- (Comp a b) / (Comp c d) = (Comp ((a*c + b*d) / (c*c + d*d)) ((b*c - a*d) / (c*c + d*d)))
- import System.IO
- import Control.Monad
- import Data.Char
- import Data.Map (Map)
- import qualified Data.Map as Map
- main :: IO ()
- main = do
- hSetBuffering stdout NoBuffering -- DO NOT REMOVE
- -- Auto-generated code below aims at helping you parse
- -- the standard input according to the problem statement.
- input_line <- getLine
- let n = read input_line :: Int -- Number of elements which make up the association table.
- input_line <- getLine
- let q = read input_line :: Int -- Number Q of file names to be analyzed.
- let myMap = Map.fromList [("html","text/html"), ("png","image/png"), ("gif","image/gif")]
- replicateM n $ do
- input_line <- getLine
- let input = words input_line
- let ext = input!!0 -- file extension
- let mt = input!!1 -- MIME type.
- return ()
- replicateM q $ do
- fname <- getLine
- let input = dropWhile (/='.') fname
- let input2 = dropWhile (=='.') input
- putStrLn $ show $ Map.lookup input2 myMap
- -- let type = input!!1
- -- putStrLn type
- -- One file name per line.
- return ()
- -- hPutStrLn stderr "Debug messages..."
- -- For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
- putStrLn "UNKNOWN"
- return ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement