本帖最后由 C.L 于 2010-3-9 17:12 编辑
做这道题有点蛋疼,不过还是做出来了,也是笨办法.$time = TimerInit ()
$sText = _
"这是个将文章以仿古文的形式竖向排列的练习,欢迎各位童鞋参与,参与练习的均有米米发放。呵呵~" & @CR & _
"练习的要求很简单,如下(不,应该是如左):" & @CR & _
"1,将练习文本以每个章节18列竖向排列,每列文字12个,由上至下、由右及左的阅读顺序;" & @CR & _
"2,排列必须做到横纵对齐。" & @CR & _
"在此基础上能做到以下要求的更好:" & @CR & _
"1,将半角的字符转为全角,如“ABC123”;" & @CR & _
"2,能加上装饰边框线;" & @CR & _
"3,断行时需另为下一列;" & @CR & _
"4,章节填满后需往下另开新章节。" & @CR & _
"有兴趣的就来试试吧,两日内以完成时间(ms计)最短的为最佳答案(均以本人同机自测为准)。" & @CR & _
"没兴趣或者觉得太简单的就请飘过吧…" & @CR & _
"另注:" & @CR & _
"这个是加了边框线表格线的例子,在本论坛的帖子中由于行距被加大而不那么完美,在记事本中可以完美显示竖线无间断~"
$sLen = int(StringLen ($sText)/12)
$sLen = (Int ($sLen / 20)+1)*20
Global $astr [$sLen][14],$o=1
TextToArray ()
drawline ()
$result = arrayToStr()
MsgBox (0,"用时:"&TimerDiff($time)&"ms",$result)
Func arrayToStr ()
Dim $e=19,$s=0,$finish=""
While $e < $sLen
$finish = xx($s,$e)&@CRLF&$finish
$s=$e+1
$e+=20
WEnd
Return $finish
EndFunc
Func xx ($s,$e)
Dim $sOut = ""
For $m = 0 to 13
For $n = $s To $e
$sTem = $astr[$n][$m]
If $sTem <> "" Then
$sOut &= $sTem
Else
$sOut &= $sTem&" │"
EndIf
If Mod($n,20)==19 And $n <> 0 Then
$sOut &= @crlf
EndIf
Next
Next
Return $sOut
EndFunc
Func drawline ()
For $n = $sLen -1 To 0 step -1
For $m = 0 to 13
If Mod ($n,20)==0 Or Mod ($n,20)==19 Then
If $m == 0 Or $m == 13 Then
$astr [$n][$m] = "╃"
Else
$astr [$n][$m] = "║"
EndIf
Else
if $m == 0 Then
$astr [$n][$m] = "─┬"
elseIf $m == 13 Then
$astr [$n][$m] = "─┴"
EndIf
EndIf
Next
Next
EndFunc
Func TextToArray ()
For $n = $sLen -1 To 0 step -1
For $m = 0 to 13
If Mod ($n+1,20)==0 Then ExitLoop
If $m <> 0 And $m <> 13 Then
$tText = StringMid ($sText,$o,1)
If $tText == @CR Or $tText == "" Then
$o+=1
ExitLoop
EndIf
If AscW($tText) >= 32 AND AscW($tText) <= 126 Then $tText = ChrW(65248 + AscW($tText))
;~ MsgBox (0,"",$tText&@cr&$n&@cr&$m)
If Mod ($n,20)==0 Or Mod ($n,20)==18 Then
$astr [$n][$m]= $tText
Else
$astr [$n][$m] = $tText&"│"
EndIf
$o+=1
EndIf
Next
Next
EndFunc
再贴个运行图:
|