Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
67
Task/Align-columns/Yabasic/align-columns.basic
Normal file
67
Task/Align-columns/Yabasic/align-columns.basic
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
theString$ = "Given$a$text$file$of$many$lines,$where$fields$within$a$line$"
|
||||
theString$ = theString$ + "are$delineated$by$a$single$'dollar'$character,$write$a$program"
|
||||
theString$ = theString$ + "that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$"
|
||||
theString$ = theString$ + "column$are$separated$by$at$least$one$space."
|
||||
theString$ = theString$ + "Further,$allow$for$each$word$in$a$column$to$be$either$left$"
|
||||
theString$ = theString$ + "justified,$right$justified,$or$center$justified$within$its$column."
|
||||
|
||||
x = shoTable(theString$, "left", 6)
|
||||
x = shoTable(theString$, "right", 6)
|
||||
x = shoTable(theString$, "center", 6)
|
||||
end
|
||||
|
||||
sub word$(sr$, wn, delim$)
|
||||
local i, j, n, sd, sl, sl2
|
||||
local s$, res$, d$
|
||||
|
||||
d$ = delim$
|
||||
j = wn
|
||||
if j = 0 j = j+1
|
||||
res$ = "" : s$ = sr$
|
||||
if d$ = "" d$ = " "
|
||||
sd = len(d$) : sl = len(s$)
|
||||
do
|
||||
n = instr(s$,d$)
|
||||
j = j - 1
|
||||
if j = 0 then
|
||||
if n = 0 then res$ = s$ else res$ = mid$(s$, 1, n-1) : fi
|
||||
return res$
|
||||
fi
|
||||
if n = 0 return res$
|
||||
if n = sl-sd then res$ = "" : return res$ : fi
|
||||
sl2 = sl-n
|
||||
s$ = mid$(s$, n+1, sl2)
|
||||
sl = sl2
|
||||
loop
|
||||
return res$
|
||||
end sub
|
||||
|
||||
sub shoTable(theString$, align$, across)
|
||||
local i, a$, b$
|
||||
|
||||
print "------------ align:", align$, " -- across:", across, " ------------"
|
||||
dim siz(across)
|
||||
b$ = " "
|
||||
while word$(theString$, i+1, "$") <> ""
|
||||
siz(mod(i, across)) = max(siz(mod(i, across)), len(word$(theString$, i+1, "$")))
|
||||
i = i+1
|
||||
wend
|
||||
for i = 0 to across - 1
|
||||
siz(i) = siz(i)+1
|
||||
if siz(i) and 1 siz(i) = siz(i)+1
|
||||
next i
|
||||
|
||||
i = 0
|
||||
a$ = word$(theString$, i+1, "$")
|
||||
while a$ <> ""
|
||||
s = siz(mod(i, across)) - len(a$)
|
||||
if align$ = "right" a$ = left$(b$, s) + a$
|
||||
if align$ = "left" a$ = a$ + left$(b$, s)
|
||||
if align$ = "center" a$ = left$(b$, int(s / 2)) + a$ + left$(b$, int(s / 2) + (s and 1))
|
||||
print "|", a$;
|
||||
i = i + 1
|
||||
if mod(i, across) = 0 print "|"
|
||||
a$ = word$(theString$, i+1, "$")
|
||||
wend
|
||||
print
|
||||
end sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue