Skip to content

Instantly share code, notes, and snippets.

@cojna
Created June 28, 2013 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cojna/5883542 to your computer and use it in GitHub Desktop.
Save cojna/5883542 to your computer and use it in GitHub Desktop.
https://gist.github.com/cojna/5857876 の答え的なもの. main関数をたくさん書いているので,このファイルはコンパイルできません.
import Control.Applicative ((<$>), (<*>), liftA2)
import Control.Monad (forM, replicateM)
import Data.Function (on)
main = do
x <- getLine
y <- getLine
print $ read x + read y
main = do
x <- fmap read getLine
y <- read <$> getLine
print $ x + y
main = do
x <- readLn
y <- readLn
print $ x + y
main = do
res <- (+) <$> readLn <*> readLn
print res
main = do
res <- liftA2 (+) readLn readLn
print res
main = do
f <- (+) <$> readLn
x <- readLn
return $ f x
main = do
res <- ((+) `on` read) <$> getLine <*> getLine
print res
main = do
xs <- forM [1..2] $ \_ -> do
x <- getLine
return $ read x
print $ sum xs
main = do
xs <- replicateM 2 readLn
print $ foldl (+) 0 xs
main = do
[x, y] <- sequence [readLn, readLn]
print $ x + y
main = do
[x, y] <- map read . words <$> getContents
print $ x + y
main=interact$show.sum.map read.words
main = (+) <$> readLn <*> readLn >>= print
main = replicateM 2 readLn >>= print . sum
main = getContents >>= print . foldr ((+) . read) 0 . words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment