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.
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 , 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 , and the block size is . The image is broken into blocks of size . The gray values within each block are averaged, and then are converted to the appropriate character. The final output is shown on the right.
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.
The output consists of exactly lines, each containing exactly characters (followed immediately by the end of line). There should be no initial or trailing blanks on each output line.
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
Input 1 | Output 1 |
---|---|
Input 2 | Output 2 |
Input 3 | Output 3 |
Input 4 | Output 4 |
Input 5 | Output 5 |
Input 6 | Output 6 |