UVa445 - Marvelous Mazes-字符串-难度1

来源:互联网 发布:淘宝产品上下架时间 编辑:程序博客网 时间:2024/05/16 02:05

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=386


 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 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*1T 11X21b1X4X1b1X

Sample Output

T TTTTTT  T TTT T  TTT   T TTTT   TT   T TTTTTT*T XX   XXXXX X

代码:

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. /* 
  2.  *1)Descriptions for different mazes will be separated by a blank line  
  3.  *in both input and output.空行表示就是一个回车的行,没有空格。 
  4.  *2)The descriptions for different rows in the maze will be separated 
  5.  *  by an exclamation point (!) or by an end of line.表示以'!'或者'\n'为 
  6.  *  结束 
  7.  */  
  8. #include <iostream>  
  9. #include <string>  
  10. #include <cstdio>  
  11. #include <cctype>  
  12. using namespace std;  
  13.   
  14. int main()  
  15. {  
  16. #ifdef LOCAL  
  17.     freopen("f:\\input.txt""r", stdin);  
  18. #endif LOCAL  
  19.     char c;  
  20.     int count = 0;//用来记总的字数  
  21.     while(scanf("%c", &c) != EOF)//EOF end of file  
  22.     {  
  23.         if(isdigit(c))  
  24.         {  
  25.             count += c - '0';  
  26.         }  
  27.         else if(isupper(c) || c == '*')  
  28.         {  
  29.             while(count)  
  30.             {  
  31.                 cout << c;  
  32.                 count--;  
  33.             }  
  34.             /* 
  35.              *如果用: 
  36.              *while(count--) 
  37.              *{ 
  38.              *  cout << c; 
  39.              *} 
  40.              *最后count为-1,所以还要把count置为0 
  41.              */  
  42.         }  
  43.         else if(c == 'b')  
  44.         {  
  45.             while(count)  
  46.             {  
  47.                 cout << " ";  
  48.                 count--;  
  49.             }  
  50.         }  
  51.         else if(c == '!' || c == '\n')  
  52.         {  
  53.             cout << endl;  
  54.             count = 0;  
  55.         }  
  56.     }  
  57.     return 0;  
  58. }  
0 0