Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mkut
committed
May 3, 2012
1 parent
6b27b94
commit 045e895
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
main |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
################################ | ||
## Makefile for Haskell | ||
## Author: mkut | ||
## Date : 2012.4.16 | ||
## Rev : 0.1 | ||
################################ | ||
|
||
## project settings | ||
TARGET = main | ||
SOURCES = haskell.hs | ||
MILIBS = IO Contest | ||
|
||
## command settings | ||
HC = ghc | ||
HCFLAGS = --make -O | ||
|
||
## directory settings | ||
MILIB_DIR = /home/mkut/milib/haskell | ||
|
||
## file name macros | ||
OBJS = $(SOURCES:%.hs=%.hi) $(SOURCES:%.hs=%.o) | ||
MILIB_SRC = $(MILIBS:%=$(MILIB_DIR)/%.hs) | ||
|
||
## make rules | ||
.PHONY: default clean | ||
|
||
default: $(TARGET) | ||
|
||
$(TARGET): $(SOURCES) $(MILIB_SRC) | ||
$(HC) $(HCFLAGS) -o $@ $^ | ||
rm $(OBJS) | ||
|
||
clean: | ||
rm -f *.o $(TARGET) $(OBJS) $(GEN_OBJS) |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE Rank2Types #-} | ||
-- import Milib.Contest | ||
-- import Milib.IO | ||
|
||
import IO | ||
import qualified Data.ByteString.Lazy.Char8 as C | ||
import Text.Parsec.Prim | ||
import Text.Parsec.Combinator | ||
import Text.Parsec.Char | ||
import Data.Functor.Identity | ||
import Control.Monad | ||
import Text.Printf | ||
|
||
main = contestMain p solve number | ||
|
||
solve y | ||
| y `mod` 400 == 0 = True | ||
| y `mod` 100 == 0 = False | ||
| y `mod` 4 == 0 = True | ||
| otherwise = False | ||
|
||
p h True = hPutStrLn h "YES" | ||
p h False = hPutStrLn h "NO" | ||
|
||
-- Milib.Contest | ||
|
||
type Printer a = Handle -> a -> IO () | ||
type Solver a b = a -> b | ||
type Parser b = Stream C.ByteString Identity Char => Parsec C.ByteString () b | ||
type CMain a b = Printer b -> Solver a b -> Parser a -> IO () | ||
type HCMain a b = Handle -> Handle -> CMain a b | ||
|
||
instance Stream C.ByteString Identity Char where | ||
uncons = return . C.uncons | ||
|
||
hContestMain :: HCMain a b | ||
hContestMain hin hout printer solver parser = do | ||
input <- C.hGetContents hin | ||
case parse parser "" input of | ||
Left err -> do { hPutStr stderr "parse err: "; hPrint stderr err } | ||
Right x -> printer hout $ solver x | ||
|
||
contestMain :: CMain a b | ||
contestMain = hContestMain stdin stdout | ||
|
||
-- Milib.IO | ||
number' :: Stream s m Char => ParsecT s u m Int | ||
number' = | ||
do ds <- many1 digit | ||
return (read ds) | ||
<?> "number" | ||
|
||
number :: Stream s m Char => ParsecT s u m Int | ||
number = do spaces; number' | ||
|
||
-- vim: set expandtab: |
Empty file.