Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
21
Task/Odd-word-problem/Haskell/odd-word-problem-1.hs
Normal file
21
Task/Odd-word-problem/Haskell/odd-word-problem-1.hs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import System.IO
|
||||
(BufferMode(..), getContents, hSetBuffering, stdin, stdout)
|
||||
import Data.Char (isAlpha)
|
||||
|
||||
split :: String -> (String, String)
|
||||
split = span isAlpha
|
||||
|
||||
parse :: String -> String
|
||||
parse [] = []
|
||||
parse l =
|
||||
let (a, w) = split l
|
||||
(b, x) = splitAt 1 w
|
||||
(c, y) = split x
|
||||
(d, z) = splitAt 1 y
|
||||
in a <> b <> reverse c <> d <> parse z
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
hSetBuffering stdin NoBuffering >> hSetBuffering stdout NoBuffering >> getContents >>=
|
||||
putStr . takeWhile (/= '.') . parse >>
|
||||
putStrLn "."
|
||||
31
Task/Odd-word-problem/Haskell/odd-word-problem-2.hs
Normal file
31
Task/Odd-word-problem/Haskell/odd-word-problem-2.hs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
isAlpha :: Char -> Bool
|
||||
isAlpha = flip elem $ ['a'..'z'] ++ ['A'..'Z']
|
||||
|
||||
parse :: IO ()
|
||||
parse = do
|
||||
x <- getChar
|
||||
putChar x
|
||||
case () of
|
||||
_ | x == '.' -> return ()
|
||||
| isAlpha x -> parse
|
||||
| otherwise -> do
|
||||
c <- revParse
|
||||
putChar c
|
||||
if c == '.'
|
||||
then return ()
|
||||
else parse
|
||||
|
||||
revParse :: IO Char
|
||||
revParse = do
|
||||
x <- getChar
|
||||
case () of
|
||||
_ | x == '.' -> return x
|
||||
| isAlpha x -> do
|
||||
c <- revParse
|
||||
putChar x
|
||||
return c
|
||||
| otherwise -> return x
|
||||
|
||||
main :: IO ()
|
||||
main = hSetBuffering stdin NoBuffering >> hSetBuffering stdout NoBuffering >>
|
||||
parse >> putStrLn ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue