Tiling Problem ------ ------- If sub-windows of a computer screen window are not sup- posed to overlap, determining the placement of these sub-windows can be difficult. This problem addresses a simple case of non-overlapping sub-window placement. We will call the sub-windows `tiles', and abstract the problem by considering windows and tiles to be squares of characters. Thus saying that a window (or tile) has size N means the window (or tile) consists of NxN characters. The problem is, given a window of size N, and tiles named A, B, C, ... of sizes sA, sB, sC, ..., place the tiles in the window. The position of a tile is its upper left corner. The window is blank before any tile is placed, meaning that all its characters are the space character. When a tile is placed, its name, which is a single character, is copied into all the window charac- ters occupied by the tile. In this problem tiles are placed in order of their name, and a strict left-to-right top-to-bottom scan is used to find positions for tiles. The first tile, which is always tile A, is always placed in the upper left corner of the window. Then the scan proceeds from the position of the last tile placed until the first posi- tion is arrived at where the next tile can be placed, without overlapping any previously placed tile. That position is used as the position of the next tile. Each tile must be completely inside the window. If a tile cannot be placed by the scan, the tile is ignored, and not placed at all. The scan always resumes from the position of the last tile placed (except when placing the first tile), and the scan never goes up, and never goes to the left except just after going down. Input ----- For each case, one or more lines containing non-negative integers in the following order: the size N of the window, 0 < N <= 80 the sizes sA, sB, sC, ... of the tiles in order the value 0 (which ends the case description) Each tile size s is such that 0 < s <= N. There may be at most 26 tiles, named A through Z, and their sizes are given in the order of their names. Numbers may be sepa- rated, preceded, and followed by any combination of spaces and tabs. A case may be spread across several lines. Input ends with an end of file. Output ------ For each case, a line containing a single `-' and noth- ing else, followed by the N lines of the window. Each window line consists of the character `|' followed by the N characters of the window line followed by `|', and nothing else. There are no spaces or tabs in the out- put, except for spaces in the window. Sample Input ------ ----- 8 1 2 3 4 5 0 8 5 4 3 2 1 0 Sample Output ------ ------ - |ABBCCC | | BBCCC | | CCC | |DDDD | |DDDD | |DDDD | |DDDD | | | - |AAAAACCC| |AAAAACCC| |AAAAACCC| |AAAAADDE| |AAAAADD | | | | | | | File: tile.txt Author: Bob Walton Date: Thu Oct 21 05:38:49 EDT 2004 The authors have placed this file in the public domain; they make no warranty and accept no liability for this file. RCS Info (may not be true date or author): $Author: walton $ $Date: 2004/10/21 09:42:10 $ $RCSfile: tile.txt,v $ $Revision: 1.4 $