1994 ACM Student Programming Contest

Pacific Region


Problem D: Columnar Tabulation

Many word processing systems provide for specifying logical
tabs in data which result in physical tabs on typewriters or
equivalent spacing on printers.  A tab request will cause
spaces to be inserted up to the next tab column (tab stop)
beyond the current position.  For this problem, "current
position" is defined as the column about to be printed.  A
tab request when the current position is a tab stop results
in tabbing to the next tab stop.  A tab request when no
further tab stop is set results in moving right one space.
In this problem, a tab character is #, and there may be more
than one # in succession, causing insertion of spaces for
each # according to the preceding rules.

Write a program which reads pairs of data records until end
of file.  The first record of each pair contains a variable
number of integer numbers representing columnar tab stops.
Numbers begin in column 1 and are separated by one space.
An end of line character immediately follows the last
number.  The second record of each pair contains a line of
text with embedded tab characters.  Input data records and
output print lines will be at most 70 characters long. Any
printing beyond column 70 is to be suppressed.

For each input data record pair, print the data as read,
then print a two-line column heading as shown below,
followed by the print line as formatted with spaces inserted
according to the tab characters.  For example, the following
input data:

9  15 16  17  21  25  32
This #data uses  ##the tab#feature

produces these print lines:

9  15  16  17  21  25  32
This #data uses  ##the tab#feature
0        1          2         3         4         5         6         7
12345678901234567989012345678901234567890123456789012345678901234567890
This    data uses        the tab feature

Print data sets as above, with each set separated by at
least one blank line.  Note that the 2-line column heading
associated with each output data set serves to identify the
print column in which each output data line character
appears; output data characters must align with the correct
column.

lazowska@cs.washington.edu