-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaskell.hs
55 lines (43 loc) · 1.26 KB
/
haskell.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
43
44
45
46
47
48
49
50
51
52
53
54
55
import System.IO
import Control.Monad
average a b =
(a + b) `div` 2
calcNextPos (x0, x1) (y0, y1) =
(average x0 x1, average y0 y1)
calcRangeX bombDir x (x0, x1) =
if elem 'L' bombDir then
(x0, x - 1)
else if elem 'R' bombDir then
(x + 1, x1)
else
(x0, x1)
calcRangeY bombDir y (y0, y1) =
case head bombDir of
'U' -> (y0, y - 1)
'D' -> (y + 1, y1)
_ -> (y0, y1)
solve x y rangeX rangeY = forever $ do
input_line <- getLine
let bombDir = input_line :: String
let rangeX' = calcRangeX bombDir x rangeX
let rangeY' = calcRangeY bombDir y rangeY
let (x', y') = calcNextPos rangeX' rangeY'
-- hPutStrLn stderr "Debug messages..."
putStrLn $ show x' ++ " " ++ show y'
solve x' y' rangeX' rangeY'
main :: IO ()
main = do
hSetBuffering stdout NoBuffering -- DO NOT REMOVE
input_line <- getLine
let inputs = words input_line
let w = read (inputs!!0) :: Int
let h = read (inputs!!1) :: Int
input_line <- getLine
let n = read input_line :: Int
input_line <- getLine
let inputs2 = words input_line
let x = read (inputs2!!0) :: Int
let y = read (inputs2!!1) :: Int
let xRange = (0, w - 1)
let yRange = (0, h - 1)
solve x y xRange yRange