Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
20
Task/Odd-word-problem/Haskell/odd-word-problem-1.hs
Normal file
20
Task/Odd-word-problem/Haskell/odd-word-problem-1.hs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import System.IO
|
||||
|
||||
isAlpha :: Char -> Bool
|
||||
isAlpha = flip elem $ ['a'..'z'] ++ ['A'..'Z']
|
||||
|
||||
split :: String -> (String, String)
|
||||
split = break $ not . 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