Internet Conciseness Programming Contest: Round 5

Authors

Publication

Pub Details

Date

Pages

See all articles from QL Hacker's Journal 15

In past issues of the QHJ I’ve covered this contest. I’ve included Round 5 for completeness – ED

PAPER FOLDING

You are given a sheet of paper that contains all asterisks (‘*’) on top, and all pound signs (‘#’) on the bottom. A three by five sheet of this paper would look like this:

        *****
*****
*****

on top, and this:

        #####
#####
#####

on the bottom. If you were to make a vertical fold in the paper one unit from the right edge of the paper, the resulting paper would look like this:

        ***#
***#
***#

on top. For this round, you will be writing a program which, given the dimensions of a piece of paper with asterisks on top and pound signs on the bottom, will show how that piece of paper looks after a number of folds have been made in it.

The Input

There will be multiple data sets in the input file. Each data set will start with two numbers on a single line separated by a space ( 1 <= x <= 10, 1 <= y <= 10 ). These are the dimensions of the piece of paper — x rows and y columns. The next line of the data set contains a single number which indicates the number of folds you are to make in the piece of paper. The next lines will each contain a description of a fold in the form

ED N

where E is either ‘T’, ‘B’, ‘L’, or ‘R’ (meaning ‘top’, ‘bottom’, ‘left’, and ‘right’ respectively); D is either ‘O’ or ‘U’ (meaning ‘over’ or ‘under’ respectively; and N is an integer indicating how many units from the edge you are to make the fold. E will always be in column 1, D will always be in column 2, a space will always be in column 3, and N will always start in column 4. The specifiers E, D, and N mean that you are to fold the E edge of the paper in the direction D at a point N units from the E edge. Thus, a line which reads

RO 1

means you are to fold the right side of the paper over, one unit from the current rightmost edge of the paper. A line reading

BU 3

means you are to fold the current bottom edge of the paper under, three units from the current bottom edge.

The Output

Produce as output what the paper looks like after all folds have been made. Left justify your output, and print a blank line between data sets.

Sample Input

3 5
1
RO 1
4 6
2
BU 1
RO 1
6 6
1
LU 5

Sample Output

***#
***#
***#

****#
****#
*****

*####
*####
*####
*####
*####
*####

Products

 

Downloadable Media

 

Image Gallery

Scroll to Top