data b; file f; text n, t; list c, r, s; integer a, i, k, m, w; b = "Given$a$text$file$of$many$lines,$where$fields$within$a$line$\n" "are$delineated$by$a$single$'dollar'$character,$write$a$program\n" "that$aligns$each$column$of$fields$by$ensuring$that$words$in$each$\n" "column$are$separated$by$at$least$one$space.\n" "Further,$allow$for$each$word$in$a$column$to$be$either$left$\n" "justified,$right$justified,$or$center$justified$within$its$column."; f.b_affix(b); m = 0; while (f.news(r, 0, 0, "$") ^ -1) { c.append(r); m = max(m, ~r); } i = 0; while (i < m) { w = 0; for (, r in c) { if (i < ~r) { w = max(w, length(r[i])); } } s.append(w + 1); i += 1; } for (k, t in list("left", "center", "right")) { o_(t, " justified\n"); for (, r in c) { for (i, n in r) { m = s[i] - ~n; o_form("/w~3/~/w~1/", a = (2 - k) * m >> 1, "", m - a, "", n); } o_newline(); } o_newline(); }