Functional Programming Contest - September'14

3439 단어
경기 링크
A제
1 -- Enter your code here. Read input from STDIN. Print output to STDOUT

2 main = do

3     x <- getLine

4     y <-  getLine

5     putStrLn $ reverse $ foldl (\acc (x, y) -> [y]++[x]++acc) [] $ zip x y

B제
1 -- Enter your code here. Read input from STDIN. Print output to STDOUT

2 import Data.List

3 main = do

4     inputdata <- getLine

5     putStrLn . concat . map (\xs -> f (head xs) (length xs)) . group $ inputdata 

6         where 

7             f ch len

8                 | len == 1 = [ch]

9                 | otherwise = [ch] ++ show len

C 문제
 1 -- Enter your code here. Read input from STDIN. Print output to STDOUT

 2 import Data.Char

 3 main::IO ()

 4 main = getContents >>= print . (\[n, k] -> superDigit ((read k) * getStrSum(n))) . words

 5 

 6 superDigit::Int -> Int

 7 superDigit n

 8     | n < 10 = n

 9     | otherwise = superDigit . getSum $ n

10 

11 getSum::Int -> Int

12 getSum 0 = 0

13 getSum n  = (n `rem` 10) + getSum ( n `div` 10)

14 

15 getStrSum::String -> Int

16 getStrSum [] = 0

17 getStrSum (x:xs) = ord x - ord '0' + getStrSum xs 

D제
 
E제

좋은 웹페이지 즐겨찾기