Last active
October 22, 2017 14:43
-
-
Save qnikst/a06ebe89274fd56b58372e3f9e37ba76 to your computer and use it in GitHub Desktop.
special-olympics
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
{-# Language OverloadedStrings #-} | |
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} | |
module Main where | |
import qualified Data.ByteString.Char8 as BS8 | |
import qualified Data.ByteString.Lazy as BSL | |
import qualified Data.ByteString.FastBuilder as Builder | |
-- import qualified Data.ByteString.Builder.Extra as Builder | |
import Data.ByteString.Char8 (ByteString) | |
import Data.Monoid ((<>)) | |
import qualified Data.Vector as V | |
import GHC.Exts | |
import System.IO | |
main :: IO () | |
main = do | |
ws <- BS8.lines <$> BS8.getContents | |
let s = V.map (\v -> case BS8.words v of | |
(a:_) -> a) | |
$ V.fromList ws | |
BSL.hPutStr stdout | |
$ Builder.toLazyByteStringWith 110000 110000 | |
$ foldMap (\suff -> | |
V.foldr (\pref nx -> Builder.byteString suff | |
<> Builder.byteString pref | |
<> Builder.char8 '\n' | |
<> nx) mempty (mkP ws)) s | |
{-# NOINLINE mkP #-} | |
mkP = V.map (\v -> case BS8.words v of | |
(_:b:_) -> b) | |
. V.fromList |
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
{-# Language OverloadedStrings #-} | |
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-} | |
module Main where | |
import qualified Data.ByteString.Char8 as BS8 | |
import qualified Data.ByteString.Lazy as BSL | |
import qualified Data.ByteString.FastBuilder as Builder | |
import Data.ByteString.Char8 (ByteString) | |
import Data.Monoid ((<>)) | |
import qualified Data.Vector as V | |
import System.IO | |
main :: IO () | |
main = do | |
ws <- BS8.lines <$> BS8.getContents | |
let (s,p) = V.unzip | |
$ V.map (\v -> case BS8.words v of | |
[z,k] -> (z,k)) | |
$ V.fromList ws | |
hSetBuffering stdout (BlockBuffering Nothing) | |
BSL.hPutStr stdout | |
$ Builder.toLazyByteStringWith 110000 110000 | |
$ foldMap (\suff -> | |
foldMap (\pref -> Builder.byteString suff | |
<> Builder.byteString pref | |
<> Builder.char8 '\n') p) s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment