Your program will get the information for the mazes from the input file. This file will contain 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. Ifthere 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 lower case 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.
1T1b5T!1T2b1T1b2T!1T1b1T2b2T!1T3b1T1b1T!3T3b1T!1T3b1T1b1T!5T1*1T
11X21b1X
4X1b1X
Output:T TTTTT
T T TT
T T TT
T T T
TTT T
T T T
TTTTT*T
XX X
XXXX X
//marvelous mazes:译为神奇的迷宫,是一个数字、字符串处理程序
//问题分析:1、首先是输入是否存储,存储选择的数据结构是什么;要求行的数目不限,但是每一行要求不超过132个,所以考虑用指针
//字符串处理问题,两种方式最好解决,第一种是getchar一个一个读取,第二种是使用二维字符数组,使用指针有很多细节问题不推荐使用。
// 2、第二个问题是字符串中存在数字,要进行按位提取分析,数字只有两种情况,一种是一位数字,一种是两位数字
// 3、单独的空行处理拿出来说,其实空行就可以看作是仅仅有一个换行符的一行字符串,由此均可以归结到读取字符串进行判定
//字符与数字的转换。。字符串中的数字转换为实际的数字,如何实现,.....ch-'0'.....
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char ch;
int num=0,i=0;
while((ch=getchar())!=EOF)
{
if(isdigit(ch))
{
num +=ch-'0';//********问题~~,注意“+=”与num变量之间要加空格*********
continue;
}
else if(ch=='b')
ch=' ';
else if(ch=='!'||ch=='\n')
{
printf("\n");
continue;
}
for(i=0;i<num;i++)
printf("%c",ch);
num=0;
}
return 0;
}