はじめてのHaskell(7)

練習問題

countbyte.hs

main = do cs <- getContents
          print $ countByte cs

countByte cs = length cs 

countwords.hs

main = do cs <- getContents
          print $ countWords cs

countWords cs = length $ words cs

swap.hs

main = do cs <- getContents
          putStr $ swap cs

swap :: String -> String
swap cs = concatMap expandA cs

expandA :: Char -> String
expandA 'a' = ['A']
expandA 'A' = ['a']
expandA c = [c]

sort.hs

import System
import List

main = do cs <- getContents
          putStr $ unlines $ sort $ lines cs 

uniq.hs

import List

main = do cs <- getContents
          putStr $ unlines $ remdup $ group $ sort $ lines cs
	   where
	    remdup :: [[a]] -> [a]
	    remdup [] = []
	    remdup (x:xs) = head x :remdup xs

uniq2.hs

import List

main = do cs <- getContents
          putStr $ unlines $ map head $ group $ lines cs
広告を非表示にする