June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
34
Task/Align-columns/BaCon/align-columns.bacon
Normal file
34
Task/Align-columns/BaCon/align-columns.bacon
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
DECLARE in$[] = { "Given$a$text$file$of$many$lines,$where$fields$within$a$line$", \
|
||||
"are$delineated$by$a$single$'dollar'$character,$write$a$program", \
|
||||
"that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$", \
|
||||
"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." }
|
||||
|
||||
OPTION DELIM "$"
|
||||
|
||||
CONST items = 6
|
||||
|
||||
SUB Print_In_Columns(style)
|
||||
|
||||
' Find widest column
|
||||
FOR y = 0 TO items-1
|
||||
FOR x = 1 TO AMOUNT(in$[y])
|
||||
IF LEN(TOKEN$(in$[y], x)) > max THEN max = LEN(TOKEN$(in$[y], x))
|
||||
NEXT
|
||||
NEXT
|
||||
|
||||
' Print aligned
|
||||
FOR y = 0 TO items-1
|
||||
FOR x = 1 TO AMOUNT(in$[y])
|
||||
PRINT ALIGN$(TOKEN$(in$[y], x), max+1, style);
|
||||
NEXT
|
||||
PRINT
|
||||
NEXT
|
||||
PRINT
|
||||
|
||||
END SUB
|
||||
|
||||
Print_In_Columns(0)
|
||||
Print_In_Columns(1)
|
||||
Print_In_Columns(2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue