[Problem-solving report] Marvelous Mazes

Subject to the effect

Original title: http://uva.onlinejudge.org/external/4/445.pdf

background

Title was simply making a maze, the number of characters that appear behind the front will equal the sum of the numbers appear, 'b' is replaced by a space, '!' It is '\ n' instead of '*' is not changed.

 

Sample Input

1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T

11X21b1X
4X1b1X

 

Sample Output

T TTTTT
T  T TT
T T  TT
T   T T
TTT   T
T   T T
TTTTT*T

XX   X
XXXX X

algorithm:

Be sure to note that the input line, this line will be a maze output, rather than waiting for the completion of all of the inputs are to appear maze, I started to tangle here for a long time. This question is there perhaps someone like me to see a long list of string with a string thought to solve the problem, but to solve a character dismantling down might be much better, so make full use of the input buffer role, a character reads, and reads an output a result, there is this question so I understand that to make full use of c environment has something to function, this can increase the efficiency of the code.

Code: enclose here my code, you can go here to submit your code to verify that your code is correct,

 1 #include<stdio.h>
 2 #include<ctype.h>
 3 int main(void)
 4 {
 5     char ch;
 6     int count=0,i=0;
 7 
 8     while(scanf("%c",&ch)!=EOF)
 9     {
10         if(isdigit(ch))
11         {
12             count += ch - '0';
13             continue;
14         }
15         else if(isupper(ch)||ch=='b'||ch=='*')
16         {
17             for(i=0;i <count;i++)
18             {
19                 if(ch=='b')
20                 printf(" ");
21                 else
22                 printf("%c",ch);
23             }
24             count=0;
25         }
26         if(ch=='!'||ch=='\n')
27         printf("\n");
28      }
29     return 0;
30 }

 

Reproduced in: https: //www.cnblogs.com/qisong178878915/archive/2013/02/16/2913784.html

Guess you like

Origin blog.csdn.net/weixin_33829657/article/details/94237202