September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import strutils, sequtils, strfmt
|
||||
from strutils import splitLines, split
|
||||
from sequtils import mapIt
|
||||
from strfmt import format, write
|
||||
|
||||
let textinfile = """Given$a$text$file$of$many$lines,$where$fields$within$a$line$
|
||||
are$delineated$by$a$single$'dollar'$character,$write$a$program
|
||||
|
|
@ -7,16 +9,17 @@ column$are$separated$by$at$least$one$space.
|
|||
Further,$allow$for$each$word$in$a$column$to$be$either$left$
|
||||
justified,$right$justified,$or$center$justified$within$its$column."""
|
||||
|
||||
var words = textinfile.splitLines.mapIt(seq[string], it.split '$')
|
||||
var maxs = newSeq[int](max words.mapIt(int, it.len))
|
||||
var words = textinfile.splitLines.mapIt(it.split '$')
|
||||
var maxs = newSeq[int](max words.mapIt(it.len))
|
||||
|
||||
for l in words:
|
||||
for j,w in l:
|
||||
for line in words:
|
||||
for j,w in line:
|
||||
maxs[j] = max(maxs[j], w.len+1)
|
||||
|
||||
for i, align in ["<",">","^"]:
|
||||
echo(["Left", "Right", "Center"][i], " column-aligned output:")
|
||||
for l in words:
|
||||
for j,w in l:
|
||||
stdout.write w.format align & $maxs[j]
|
||||
for line in words:
|
||||
for j,w in line:
|
||||
stdout.write(w.format align & $maxs[j])
|
||||
stdout.write "\n"
|
||||
stdout.write "\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue