如何修改下面的代码以返回“字符串”,以便返回的输出显示在我的 MVC 页面上,并且还希望enteredChar
从用户那里接受。
有没有更好的方法来创建这个金字塔?
当前代码:
let enteredChar = 'F' // As Interactive window doesn't support to Read Input
let mylist = ['A'..enteredChar]
let mylistlength = mylist |> List.length
let myfunc i x tlist1 =
(for j = 0 to mylistlength-i-2 do printf "%c" ' ')
let a1 = [for p in tlist1 do if p < x then yield p]
for p in a1 do printf "%c" p
printf "%c" x
let a2 = List.rev a1
for p in a2 do printf "%c" p
printfn "%s" " "
mylist |> List.iteri(fun i x -> myfunc i x mylist)
输出:
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA