fork download
  1. {-# LANGUAGE OverloadedStrings #-}
  2. import Data.String
  3. import Data.Char
  4. import Data.List
  5. import Control.Monad
  6.  
  7. type Dengi = Double
  8. type Kofe = Double
  9. type Stranici = Double
  10.  
  11. data Kompanija = Kompanija {departamenti :: [Departament]}
  12. data Departament = Departament {imja :: String, rabi :: [Rabo4ij]}
  13. data Rabo4ij = Rabo4ij {dengi :: Dengi, kofe :: Kofe, stranici :: Stranici, rang :: Rang, ktoPoZhizni :: KtoPoZhizni}
  14. data KtoPoZhizni = Rab | Rukovoditelj
  15. data Rang = Pervij | Vtoroj | Tretij deriving Enum
  16.  
  17. vektor = Kompanija [
  18. Departament "Zakupki" $ join [ 9 `x` "me1", 3 `x` "me2", 2 `x` "me3", 2 `x` "ma1", ["me2R"]],
  19. Departament "Prodazhi" $ join [12 `x` "me1", 16 `x` "ma1", 3 `x` "an1", 2 `x` "an2", ["ma2R"]],
  20. Departament "Reklama" $ join [15 `x` "ma1", 10 `x` "ma2", 8 `x` "me1", 2 `x` "in1", ["ma3R"]],
  21. Departament "Logistika" $ join [13 `x` "me1", 5 `x` "me2", 5 `x` "in1", ["me1R"]]]
  22.  
  23. dela = [
  24. poschitat rabov,
  25. poschitat dengi,
  26. poschitat kofe,
  27. poschitat stranici,
  28. \departamenta -> poschitat dengi departamenta/poschitat stranici departamenta ]
  29.  
  30. main = mapM_ print $ transpose $ vicheslit dela vektor
  31.  
  32. vicheslit cho kompanija = [map f (departamenti kompanija) | f <- cho]
  33.  
  34. poschitat cho gde = sum $ map cho $ rabi gde
  35. rabov = const 1
  36.  
  37. menedzher = Rabo4ij 500 20 200
  38. marketolog = Rabo4ij 400 15 150
  39. inzhener = Rabo4ij 200 5 50
  40. analitik = Rabo4ij 800 50 5
  41.  
  42. x = replicate
  43. imena = map imja (departamenti vektor)
  44.  
  45. instance IsString Rabo4ij where
  46. fromString (c1:c2:r:kto) = rabo4ij where
  47.  
  48. rabo4ij = case ktoPoZhizni of
  49. Rukovoditelj -> rab {dengi = 1.5*dengi rab, kofe = 2*kofe rab, stranici = 0}
  50. _ -> rab
  51.  
  52. ktoPoZhizni = case kto of
  53. ['R'] -> Rukovoditelj
  54. [] -> Rab
  55. govno -> error $ "ploxoj ktoPoZHizni: " ++ govno
  56.  
  57. rang = toEnum (digitToInt r - 1)
  58.  
  59. rab = defaultRab {dengi = dengi defaultRab * (1+0.25*fromIntegral (fromEnum rang))} where
  60. defaultRab = (case [c1,c2] of
  61. "me" -> menedzher
  62. "ma" -> marketolog
  63. "in" -> inzhener
  64. "an" -> analitik
  65. govno -> error $ "ploxaja abbreviatura raba: " ++ govno) rang ktoPoZhizni
Success #stdin #stdout 0s 4620KB
stdin
Standard input is empty
stdout
[17.0,9612.5,350.0,3100.0,3.100806451612903]
[34.0,17550.0,760.0,4825.0,3.6373056994818653]
[36.0,16300.0,575.0,5450.0,2.9908256880733943]
[24.0,11375.0,425.0,3850.0,2.9545454545454546]