Created
January 11, 2015 12:59
-
-
Save aiya000/b42a28f1cf4989ce138a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad (replicateM) | |
| import Control.Applicative ((<$>)) | |
| type Point = (Int,Int) -- 座標を表す型 | |
| type Slash = (Point,Point) -- 図形に対する斬り込みを表す型 | |
| type Polygon = [Point] -- 図形を表す型 | |
| main :: IO () | |
| main = do | |
| points <- getNums -- A: 4つの数値を1行で入力受付 | |
| topNum <- readLn -- B: 頂点数を入力受付 | |
| tops <- replicateM topNum getNums -- C: 図形の頂点を入力受付 | |
| let slash = listToSlash points -- D: Aを斬り込み型に変換 | |
| let polygon = listToPolygon tops -- E: Cを図形型に変換 | |
| print $ slashes polygon slash -- F: 図形と斬り込みを引数に 切られた結果の図形の数を表示 | |
| getNums :: IO [Int] | |
| getNums = fmap read . words <$> getLine | |
| listToSlash :: [Int] -> Slash | |
| listToSlash xs = let [a,b,c,d] = xs | |
| in ((a,b), (c,d)) | |
| listToPolygon :: [[Int]] -> Polygon | |
| listToPolygon xss = map lToP xss | |
| where | |
| lToP xs = let [a,b] = xs in (a,b) | |
| --slashes :: Polygon -> Slash -> Int | |
| --slashes pol sl = |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment