next up previous
Next: String Similarity Up: UMD HPC98 Questions Previous: Garbage Collection

ASCII Art

ASCII art refers to a picture that is made up from only letters, numbers, punctuation marks and symbols. ASCII (pronounced ``as-kee'') stands for the America Standard Code for Information Interchange, is the character code used on most modern computers. Here is an example of using ASCII art to write a word ``TEST''. Notice how using different letters (for example, ``.'' versus ``$'') affects shading.

..............lllllllllll.llllllllll.llllllll.lllllllllll...............
.................lLl.....lLl.......lLl....lLl....lLl....................
................LlL.....LlL.......LlL...........LlL.....................
...............L$L.....L$LLlLL$..L$LLlLL$LL....L$L......................
..............L$L.....L$L..............L$L....L$L.......................
.............$L$.....$L$.......$L$....$L$....$L$........................
............$$$.....$$$$$$$$$$.$$$$$$$$.....$$$.........................

For this problem, your program will be given a black-and-white image, represented as a 2-dimensional array of real numbers. Each number is called a pixel. The pixel value 0 means black, 1 means white, and values in between 0 and 1 are shades of gray. Your program should convert this image into a collection of ASCII characters that approximate the gray values. The mapping from gray-scale values to characters is given below. (This assumes that you are displaying white characters on a black background.) Let x denote the gray-scale value.

displaymath326

Because most images use pixels that are square, but a character displayed on a typical screen is not square (it is taller than wide), your program will not necessarily convert pixels to characters on a 1-to-1 basis. Instead, you will be given a block size, specified by two integers h and w. For each block of pixels of size tex2html_wrap_inline334 , you will compute the average gray-scale value of the pixels in this block (by summing and dividing by the number of pixels in the block) and then use this average value to determine which character to print. You may assume that the image height and width are even multiples of the block height and width, respectively.

The example below illustrates this. The image size is tex2html_wrap_inline336 , and the block size is tex2html_wrap_inline338 . The image is broken into blocks of size tex2html_wrap_inline338 . The gray values within each block are averaged, and then are converted to the appropriate character. The final output is shown on the right.

Input format

The first line of the input contains two positive integers, the height H and width W of the image. You may assume that the height and width are each at most 100. The next line contains two positive integers, the block height h and block width w. The rest of the file consists of H lines of W reals. These are the gray values of the image. They are given row by row, from top to bottom, and within each row horizontally from left to right.

Output format

The output consists of exactly tex2html_wrap_inline356 lines, each containing exactly tex2html_wrap_inline358 characters (followed immediately by the end of line). There should be no initial or trailing blanks on each output line.

Examples

Input:Output:

6 6                                                    .;.
3 2                                                    EFL
0.00 0.00 0.50 0.10 0.00 0.00
0.00 0.00 0.42 0.00 0.00 0.00
0.00 0.00 0.00 0.30 0.00 0.00
0.65 0.63 0.00 0.60 0.00 0.00
1.00 1.00 0.78 1.00 0.95 1.00
1.00 1.00 1.00 1.00 0.95 1.00

Input:Output:

7 13                                                   ..lllllllllll
1 1                                                    .....lLl.....
0.0 0.0 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5    ....LlL......
0.0 0.0 0.0 0.0 0.0 0.5 0.6 0.5 0.0 0.0 0.0 0.0 0.0    ...L$L.......
0.0 0.0 0.0 0.0 0.6 0.5 0.6 0.0 0.0 0.0 0.0 0.0 0.0    ..L$L........
0.0 0.0 0.0 0.6 0.9 0.6 0.0 0.0 0.0 0.0 0.0 0.0 0.0    .$L$.........
0.0 0.0 0.6 0.9 0.6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0    $$$..........
0.0 0.9 0.6 0.9 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 
0.9 0.9 0.9 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

Test data used in judging

Input 1 Output 1
Input 2 Output 2
Input 3 Output 3
Input 4 Output 4
Input 5 Output 5
Input 6 Output 6

Our solution


next up previous
Next: String Similarity Up: UMD HPC98 Questions Previous: Garbage Collection

Chau-Wen Tseng
Tue Mar 24 16:22:12 EST 1998