设计一个放大字符串的程序–Haskell实验2-2

实验要求


module MyPicture where
import Data.Char
import Data.List

type Picture = [String]

---------------------------------------------------
say :: String -> String
--say的定义
sayit :: String -> IO ()
putIn :: Char -> Picture
sideByside  :: Picture -> Picture -> Picture
myconnect :: String -> Int -> Picture
mybreak :: [String] -> String
---------------------------------------------------

sayit = putStr.say

say str = mybreak $ myconnect str (length(str) - 1)

mybreak [] = []
mybreak (x:xs) = x ++ "\n" ++ mybreak xs

sideByside [] qs = []
sideByside ps [] = [] 
sideByside (p:ps)  (q:qs) = (p ++ "  " ++ q) : sideByside ps qs

myconnect str n
          | n == 1  = sideByside (putIn (str !! 0)) (putIn (str !! 1))
          | n > 0   = sideByside (myconnect str (n-1)) (putIn (str !! n))


putIn mychar
         | mychar == 'A' || mychar == 'a'  =  (lA)
         | mychar == 'B' || mychar == 'b'  =  (lB)
         | mychar == 'C' || mychar == 'c'  =  (lC)
         | mychar == 'D' || mychar == 'd'  =  (lD)
         | mychar == 'E' || mychar == 'e'  =  (lE)
         | mychar == 'F' || mychar == 'f'  =  (lF)
         | mychar == 'G' || mychar == 'g'  =  (lG)
         | mychar == 'H' || mychar == 'h'  =  (lH)
         | mychar == 'I' || mychar == 'i'  =  (lI)
         | mychar == 'J' || mychar == 'j'  =  (lJ)
         | mychar == 'K' || mychar == 'k'  =  (lK)
         | mychar == 'L' || mychar == 'l'  =  (lL)
         | mychar == 'M' || mychar == 'm'  =  (lM)
         | mychar == 'N' || mychar == 'n'  =  (lN)
         | mychar == 'O' || mychar == 'o'  =  (lO)
         | mychar == 'P' || mychar == 'p'  =  (lP)
         | mychar == 'Q' || mychar == 'q'  =  (lQ)
         | mychar == 'R' || mychar == 'r'  =  (lR)
         | mychar == 'S' || mychar == 's'  =  (lS)
         | mychar == 'T' || mychar == 't'  =  (lT)
         | mychar == 'U' || mychar == 'u'  =  (lU)
         | mychar == 'V' || mychar == 'v'  =  (lV)
         | mychar == 'W' || mychar == 'w'  =  (lW)
         | mychar == 'X' || mychar == 'x'  =  (lX)
         | mychar == 'Y' || mychar == 'y'  =  (lY)
         | mychar == 'Z' || mychar == 'z'  =  (lZ)
         | mychar == '0'              =  (d0)
         | mychar == '1'              =  (d1)
         | mychar == '2'              =  (d2)
         | mychar == '3'              =  (d3)
         | mychar == '4'              =  (d4)
         | mychar == '5'              =  (d5)
         | mychar == '6'              =  (d6)
         | mychar == '7'              =  (d7)
         | mychar == '8'              =  (d8)
         | mychar == '9'              =  (d9)
         | otherwise = lBlank
 where
    lA = ["  A  ", 
          " A A ",
          "A   A",
          "AAAAA",
          "A   A"]


    lB = ["BBBBB", 
          "B  B ",
          "BBBBB",
          "B  B ",
          "BBBBB"]


    lC = [" CCCC", 
          "C    ",
          "C    ",
          "C    ",
          " CCCC"]


    lD = ["DDDD ", 
          "D   D",
          "D   D",
          "D   D",
          "DDDD "]


    lE = ["EEEEE", 
          "E    ",
          "EEEEE",
          "E    ",
          "EEEEE"]


    lF = ["FFFFF", 
          "F    ",
          "FFFFF",
          "F    ",
          "F    "]


    lG = [" GGGG", 
          "G    ",
          "G    ",
          "G   G",
          " GGGG"]


    lH = ["H   H", 
          "H   H",
          "HHHHH",
          "H   H",
          "H   H"]


    lI = [" III ", 
          "  I  ",
          "  I  ",
          "  I  ",
          " III "]


    lJ = [" JJJ ", 
          "  J  ",
          "  J  ",
          "J J  ",
          " JJ  "]


    lK = ["K  K ", 
          "K K  ",
          "KK   ",
          "K K  ",
          "K  KK"]


    lL = ["L    ", 
          "L    ",
          "L    ",
          "L    ",
          "LLLLL"]


    lM = ["M   M", 
          "MM MM",
          "M M M",
          "M M M",
          "M   M"]


    lN = ["N   N", 
          "NN  N",
          "N N N",
          "N  NN",
          "N   N"]


    lO = [" OOO ", 
          "O   O",
          "O   O",
          "O   O",
          " OOO "]


    lP = ["PPPP ", 
          "P   P",
          "PPPP ",
          "P    ",
          "P    "]


    lQ = [" QQQ ", 
          "Q   Q",
          "Q Q Q",
          "Q  QQ",
          " QQQ "]


    lR = ["RRRR ", 
          "R   R",
          "RRRR ",
          "R R  ",
          "R   R"]


    lS = ["SSSSS", 
          "S    ",
          "SSSSS",
          "    S",
          "SSSSS"]


    lT = ["TTTTT", 
          "  T  ",
          "  T  ",
          "  T  ",
          "  T  "]


    lU = ["U   U", 
          "U   U",
          "U   U",
          "U   U",
          " UUU "]


    lV = ["V   V",
          "V   V",
          "V   V",
          " V V ",
          "  V  "]


    lW = ["W W W", 
          "W W W",
          "W W W",
          " W W ",
          " W W "]


    lX = ["X   X", 
          " X X ",
          "  X  ",
          " X X ",
          "X   X"]


    lY = ["Y   Y", 
          " Y Y ",
          "  Y  ",
          "  Y  ",
          "  Y  "]


    lZ = ["ZZZZZ", 
          "   Z ",
          "  Z  ",
          " Z   ",
          "ZZZZZ"]


    d0 = [" 000 ", 
          "0   0",
          "0   0",
          "0   0",
          " 000 "]


    d1 = ["  1  ", 
          "  1  ",
          "  1  ",
          "  1  ",
          "  1  "]


    d2 = [" 222 ", 
          "2   2",
          "   2 ",
          "  2  ",
          "22222"]


    d3 = ["3333 ", 
          "    3",
          " 333 ",
          "    3",
          "3333 "]


    d4 = ["4   4", 
          "4   4",
          "44444",
          "    4",
          "    4"]


    d5 = ["55555", 
          "5    ",
          "55555",
          "    5",
          "55555"]


    d6 = ["66666", 
          "6    ",
          "66666",
          "6   6",
          "66666"]


    d7 = ["77777", 
          "    7",
          "    7",
          "    7",
          "    7"]


    d8 = ["88888", 
          "8   8",
          "88888",
          "8   8",
          "88888"]


    d9 = ["99999", 
          "9   9",
          "99999",
          "    9",
          "99999"]


    lBlank = 
         ["     ", 
          "     ",
          "     ",
          "     ",
          "     "]
          

未经允许不得转载:初音未来Alpha » 设计一个放大字符串的程序–Haskell实验2-2

赞 (0)

评论 0

  • 昵称 (必填)
  • 邮箱 (选填)