Ultraviolet A 445-Marvelous Mazes

Source: Internet
Author: User

Marvelous Mazes
Your mission, if you decide to accept it, is to create a maze drawing program. A maze will consist of the alphabetic characters A-Z, * (asterisk), and spaces.


Input and Output
Your program will get the information for the mazes from the input file. this file will contain in lines of characters which your program must interpret to draw a maze. each row of the maze will be described by a series of numbers and characters, where the numbers before a character tell how many times that character will be used. if there are multiple digits in a number before a character, then the number of times to repeat the character is the sum of the digits before that character.

The lowercase letter "B" will be used in the input file to represent spaces in the maze. The descriptions for different rows in the maze will be separated by an exclamation point (!) Or by an end of line.


Descriptions for different mazes will be separated by a blank line in both input and output. The input file will be terminated by an end of file.

There is no limit to the number of rows in a maze or the number of mazes in a file, though no row will contain more than 132 characters.

Happy mazing!


Sample Input

1T1b5T! 1T2b1T1b2T! 1T1b1T2b2T! 1T3b1T1b1T! 3T3b1T! 1T3b1T1b1T! 5T1*1 T
 
11X21b1X
4X1b1X
Sample Output

T TTTTT
T TT
T TT
T
TTT T
T
TTTTT * T
 
XX X
Xxxx x: A string consisting of numbers, uppercase letters, *, and B. When s [I] = 'B', a line break is output. When it is a number, for example, s [I] = 2, s [I + 1] = 'T', two TTS are output consecutively. If consecutive numbers appear, the numbers and letters are output, output AA, for example, 11A.

# Include <stdio. h> # include <string. h> int main () {char s [140]; int I, j, sum, len; while (gets (s )! = NULL) {len = strlen (s); sum = 0; for (I = 0; I <len; I ++) {if (s [I]> = '0' & s [I] <= '9 ') /* if it is a number */sum + = s [I]-'0';/* calculate the number of outputs */else {if (s [I] = '! ')/* Line feed */printf ("\ n"); for (j = sum; j> 0; j --) {if (s [I] = 'B')/* Output Space */printf (""); else/* output letter or **/printf ("% c", s [I]);} sum = 0; /* Remember to clear the output. */} printf ("\ n");} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.