Advertisement
GerexD

hsk1

Jan 2nd, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. -- Gere Andor
  2. -- gaim2019
  3. -- 522/1
  4.  
  5. -- Funk2
  6.  
  7. import Data.Char
  8. --import Data.List.Split
  9. --------------------------------- 1.
  10. torol_szokoz :: String -> String
  11. torol_szokoz [] = []
  12. torol_szokoz (' ':xs) = torol_szokoz(xs)
  13. torol_szokoz (x:xs) = toLower x:torol_szokoz(xs)
  14.  
  15. string_buffer :: Int -> String
  16. string_buffer 0 = []
  17. string_buffer n = " " ++ string_buffer (n-1)
  18.  
  19. string_negyszog :: Int -> String -> [String]
  20. string_negyszog n s
  21. | length s>=n = take n s : string_negyszog n (drop n s)
  22. | length s>0 = [s ++ string_buffer (n-(length s))]
  23. | otherwise = []
  24.  
  25. string_oszlop :: [String] -> String
  26. string_oszlop [] = []
  27. string_oszlop [[]] = []
  28. string_oszlop [x:xs] = [x] ++ string_oszlop [xs]
  29. --------------------------------- 2.
  30. oldPhone_e :: [Char] -> Bool
  31. oldPhone_e [] = True
  32. oldPhone_e (s:sz)
  33. | last (oldPhone [s]) == ('-',0) = False
  34. | otherwise = oldPhone_e sz
  35.  
  36. oldPhone :: Num b => [Char] -> [(Char, b)]
  37. oldPhone [] = []
  38. oldPhone (s:sz)
  39. | isUpper s = ('*',1):(keres b (toLower s)):(oldPhone sz)
  40. | otherwise = (kc,kn):(oldPhone sz)
  41. where b=["1","aábc2","deéf3","ghií4","jkl5","mnoóöő6","pqrs7","tuúüűv8","wxyz9","+ 0",".,#","*"]
  42. (kc,kn) = keres b s
  43.  
  44. keres :: Num b => [[Char]] -> Char -> (Char, b)
  45. keres [] _ = ('-',0) --Nothing (me..)
  46. keres (x:xs) s
  47. | (keres_ x s 1) == ('0',0) = keres xs s -- == Nothing (me...0
  48. | otherwise = (keres_ x s 1)
  49.  
  50. keres_ :: Num t => [Char] -> Char -> t -> (Char, t)
  51. keres_ [] _ _ = ('0',0) -- Nothing (me..)
  52. keres_ (x:xs) s i
  53. | x == s && length xs == 0 = (x,i)
  54. | x == s = ((last xs),i)
  55. | otherwise = keres_ xs s (i+1)
  56. keres_ [x] _ i = (x,i) -- Just (x,i)
  57. --------------------------------- 3.
  58. valosp :: (Double, Integer)
  59. valosp = until felt iter (2,1)
  60. where
  61. felt (x, hatv) = x/2 == 0
  62. iter (x, hatv) = (x*(1/2), hatv+1)
  63. --------------------------------- 4.
  64.  
  65. --------------------------------- 5.
  66. cumul_op :: (a -> a -> a) -> [a] -> [a]
  67. cumul_op2 :: (a -> a -> a) -> [a] -> [a]
  68. cumul_op x (fej:l) = fej:cumul_op2 x (fej:l)
  69. cumul_op2 x (fej:[]) = []
  70. cumul_op2 x (fej1:fej2:l) = fej:cumul_op2 x (fej:l) where fej=(x fej1 fej2)
  71.  
  72. data COMPLEX = Comp {a :: Float, b :: Float}
  73.  
  74. instance Show COMPLEX where
  75. show (Comp a b)
  76. | b==0 = show a
  77. | b<0 = show a ++ show b ++ "i"
  78. | otherwise = show a ++ "+" ++ show b ++ "i"
  79.  
  80.  
  81. --------------------------------- 6.
  82. data BinFa a =
  83. Nodus (BinFa a) a (BinFa a)
  84. | Level
  85. deriving Show
  86.  
  87. --A listából függvény
  88. beszur :: Ord a => BinFa a -> a -> BinFa a
  89. beszur Level x = Nodus Level x Level
  90. beszur (Nodus bal a jobb) x
  91. | a == x = Nodus bal a jobb
  92. | a < x = Nodus bal a (beszur jobb x)
  93. | a > x = Nodus (beszur bal x) a jobb
  94.  
  95. --A listából függvény
  96. listabol :: Ord a => [a] -> BinFa a
  97. listabol = foldl beszur Level
  98.  
  99. --A torol függvény
  100. torol :: Ord a => BinFa a -> a -> Maybe (BinFa a)
  101. torol Level x = Nothing
  102. torol (Nodus bal a jobb) x = case compare x a of
  103. GT -> case torol jobb x of
  104. Nothing -> Nothing
  105. Just binfa -> Just (Nodus bal a binfa)
  106. LT -> case torol bal x of
  107. Nothing -> Nothing
  108. Just binfa -> Just (Nodus binfa a jobb)
  109. EQ -> torol_ (Nodus bal a jobb) x
  110.  
  111. --torol_ Level _ = Nothing
  112. torol_ :: Ord a => BinFa a -> a -> Maybe (BinFa a)
  113. torol_ (Nodus Level a Level) x = Just Level
  114. torol_ (Nodus Level a j) _ = Just j
  115. torol_ (Nodus b a Level) _ = Just b
  116. torol_ (Nodus b a j) _ = Just (Nodus b uj jj)
  117. where uj = mini j
  118. Just jj = torol j uj
  119. mini (Nodus Level uj _) = uj
  120. mini (Nodus b _ _) = mini b
  121. --------------------------------- 7.
  122. instance Num COMPLEX where
  123. (Comp a b) + (Comp c d) = (Comp (a+c) (b+d))
  124. (Comp a b) - (Comp c d) = (Comp (a-c) (b-d))
  125. (Comp a b) * (Comp c d) = (Comp (a*c - b*d) (b*d + a*d))
  126.  
  127. abs (Comp a b) = Comp (sqrt (a*a + b*b)) 0
  128.  
  129. instance Fractional COMPLEX where
  130. (Comp a b) / (Comp c d) = (Comp ((a*c + b*d) / (c*c + d*d)) ((b*c - a*d) / (c*c + d*d)))
  131.  
  132.  
  133. import System.IO
  134. import Control.Monad
  135. import Data.Char
  136. import Data.Map (Map)
  137. import qualified Data.Map as Map
  138.  
  139. main :: IO ()
  140. main = do
  141. hSetBuffering stdout NoBuffering -- DO NOT REMOVE
  142.  
  143. -- Auto-generated code below aims at helping you parse
  144. -- the standard input according to the problem statement.
  145.  
  146. input_line <- getLine
  147. let n = read input_line :: Int -- Number of elements which make up the association table.
  148. input_line <- getLine
  149. let q = read input_line :: Int -- Number Q of file names to be analyzed.
  150.  
  151. let myMap = Map.fromList [("html","text/html"), ("png","image/png"), ("gif","image/gif")]
  152.  
  153. replicateM n $ do
  154. input_line <- getLine
  155. let input = words input_line
  156. let ext = input!!0 -- file extension
  157. let mt = input!!1 -- MIME type.
  158. return ()
  159.  
  160. replicateM q $ do
  161. fname <- getLine
  162. let input = dropWhile (/='.') fname
  163. let input2 = dropWhile (=='.') input
  164. putStrLn $ show $ Map.lookup input2 myMap
  165. -- let type = input!!1
  166. -- putStrLn type
  167. -- One file name per line.
  168. return ()
  169.  
  170. -- hPutStrLn stderr "Debug messages..."
  171.  
  172. -- For each of the Q filenames, display on a line the corresponding MIME type. If there is no corresponding type, then display UNKNOWN.
  173.  
  174. putStrLn "UNKNOWN"
  175. return ()
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement