-
Notifications
You must be signed in to change notification settings - Fork 0
/
sok.hs
42 lines (31 loc) · 1.09 KB
/
sok.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Text.Printf
main = do
a <- getLine
b <- getLine
putStrLn (sol (a, b))
sol::(String, String) -> String
sol (amounts, ratio) = frm (getdiff (prsw (amounts, ratio, (
times (prs (amounts, ratio))))))
prsr::String->[Int]
prsr a = map read (words a)
prs::(String, String) -> ([Int], [Int])
prs (frst, scnd) = ((prsr frst), (prsr scnd))
prsw::(String, String, Float) -> ([Int], [Int], Float)
prsw (frst, scnd, f) = ((prsr frst), (prsr scnd), f)
minn::(Float, Float) -> Float
minn (a, b) | a < b = a
| otherwise = b
diev::(Int, Int) -> Float
diev (a, b) = (fromIntegral a) / (fromIntegral b)
times::([Int], [Int]) -> Float
times ([], []) = 1000000
times ((a:amounts), (b:ratio)) = minn ((diev (a, b)), times (amounts, ratio))
lediff::(Int, Int, Float) -> Float
lediff (a, b, c) = (fromIntegral a) - ((fromIntegral b) * c)
getdiff::([Int], [Int], Float) -> [Float]
getdiff (a, b, c) = [
(lediff (a!!0, b!!0, c)),
(lediff (a!!1, b!!1, c)),
(lediff (a!!2, b!!2, c))]
frm::[Float]->String
frm a = (printf "%.6f" (a!!0))++" "++(printf "%.6f" (a!!1))++" "++(printf "%.6f" (a!!2))