1994 ACM Student Programming Contest

Pacific Region


Problem F: BUSBOL

In the (somewhat) mythical programming language BUSBOL
(pronounced BUZZ-BALL) positive integer numbers, referred to
below as "numbers", consist solely of one or more digits (0-
9).  Numbers may be edited with certain editing
specifications, referred to below as "edit specs".  The only
valid edit specs are the four described below.  Neither a
number nor an edit spec will exceed 20 characters.  The
result of editing a number according to an edit spec will be
referred to as the "result".

The following Edit Specs are defined in BUSBOL:

1.  Integer Alignment:  This editing applies when the edit
    spec contains only 9's.  The number is to be right justified
    with the rightmost  '9' of the edit spec.  If the edit spec
    has more 9's than the number has digits, the result will
    have leading zeroes inserted for each excess 9.  If the edit
    spec has fewer 9's than the number has digits, excess digits
    at the left of the number will be truncated.

2.  Decimal Point Insertion:  This editing applies when the
    edit spec contains a decimal point (it will never contain
    more than one decimal point).  The remaining characters in
    the edit spec will consist of one or more 9's and no other
    characters.  To obtain the result, the number should first
    be aligned according to the alignment specification for
    integer alignment (i.e., as if there were no decimal point).
    Next, the decimal point should be inserted in the number in
    the same relative position in which it exists in the edit
    spec.

3.  Zero Suppression:  This editing applies when the edit
    string consists solely of one or more upper case Z's at the
    beginning (left) followed by one or more 9's.  The number
    should first be aligned according to the specifications for
    integer alignment, treating each 'Z' as if it were a '9'.
    Next, any leading zeroes in the number which correspond to
    Z's in the edit spec should be replaced by spaces.

4.  Asterisk Fill:  This editing applies when the edit
    string consists solely of one or more *'s (asterisks) at the
    beginning (left) followed by one or more 9's.  The number
    should first be aligned according to the specifications for
    integer alignment, treating each '*' as if it were a '9'.
    Next, an leading zeroes in the number which correspond to
    *'s in the edit spec should be replaced by *'s.

Write a program which reads a file containing pairs of input
lines.  The first line in each input pair will contain a
valid BUSBOL number, immediately followed by end of line.
The second line in each pair will contain a valid BUSBOL
edit spec, immediately followed by end of line.  For each
input pair, your program is to output on a separate line,
starting in column 1 of each line, the result of editing the
input number according to its edit spec.

For example, given the following input file:

12345
99999
12345
9999999
012345
999
12345
999.99
1023
ZZZZ99
0500
***9999999

the program should produce the following output

12345
0012345
345
123.45
  1023
***0000500

lazowska@cs.washington.edu