Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let Words = ["4815"; "ucwie"; "test"; "sts"; "third"; "1"; "4815"; "ucwie"; "word"; "a"]
- type lineElement =
- |Word of string
- |Space of int
- let rec lineCreator' linesList list length line free =
- match list with
- |hd::tl ->
- let element = Word(hd)
- if (String.length hd) <= free then
- let line' = line @ [element]
- match tl with
- |next::nextList ->
- if String.length next + 1 <= free - String.length hd then
- let line'' = line' @ [Space(1)]
- let NowFree = free - String.length hd - 1
- lineCreator' linesList tl length line'' NowFree
- else
- lineCreator' linesList tl length line' 0
- |_ ->
- lineCreator' linesList tl length line' 0
- else
- let linesList' = linesList @ [line]
- lineCreator' linesList' list length [] length
- |_->
- let linesList' = linesList @ [line]
- linesList'
- //отличная идея: чтобы избавиться от лишнего пробела в конце строки, перевернем ее, откусим голову,
- //перевернем снова! (рука не поднялась реализовывать)
- let lineCreator listWords length = lineCreator' [] listWords length [] length //вместо обертки
- let abc = lineCreator Words 10 //пока работает только первая функция
- //пробуем печатать
- let rec spacePrint times =
- if times <= 0 then
- ()
- else
- printf " "
- spacePrint (times - 1)
- let rec matchingLine line =
- match line with
- |element::lineTail ->
- match element with
- |Space(k) ->
- spacePrint k
- matchingLine lineTail
- |Word(k) ->
- printf "%s" k
- matchingLine lineTail
- |_ -> ()
- |_-> ()
- let rec printLines linesList =
- match linesList with
- |line::tl ->
- matchingLine line
- printfn "."
- printLines tl
- |_ -> ()
- printLines abc
- open System
- printfn "(Press any key to continue)"
- ignore (Console.ReadKey(true))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement