-
Notifications
You must be signed in to change notification settings - Fork 0
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
Jul 1, 2012
1 parent
2a9eee8
commit 6244f34
Showing
3 changed files
with
104 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,4 @@ | ||
main | ||
in.txt | ||
out.txt | ||
ans.txt |
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 (AtCoder version) | ||
## Author: mkut | ||
## Date : 2012-5-17 | ||
## Rev : 0.1.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) |
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,66 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE Rank2Types #-} | ||
import qualified Data.ByteString.Lazy.Char8 as C | ||
import System.IO | ||
import Text.Parsec.Prim | ||
import Text.Parsec.Combinator | ||
import Text.Parsec.Char | ||
import Text.Printf | ||
import Data.Functor.Identity | ||
import Control.Monad | ||
|
||
main = contestMain printer solver parser | ||
|
||
solver = length . filter f | ||
where | ||
f "TAKAHASHIKUN" = True | ||
f "Takahashikun" = True | ||
f "takahashikun" = True | ||
f _ = False | ||
|
||
printer = hPrint | ||
|
||
parser = do | ||
n <- number | ||
ret <- count n word | ||
char '.' | ||
return ret | ||
|
||
-- 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, Integral a, Read a) => ParsecT s u m a | ||
number' = | ||
do ds <- many1 digit | ||
return (read ds) | ||
<?> "number" | ||
|
||
number :: (Stream s m Char, Integral a, Read a) => ParsecT s u m a | ||
number = do spaces; number' | ||
|
||
word' :: Stream s m Char => ParsecT s u m String | ||
word' = many1 letter | ||
|
||
word :: Stream s m Char => ParsecT s u m String | ||
word = do spaces; word' | ||
|
||
-- vim: set expandtab: |