第五章基础题目选解之习题
2014-08-12 20:31
176 查看
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.
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!
[/code]
Marvelous Mazes |
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 thenumbers 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 11X21b1X
此题需注意的就是换行的控制,不多说,代码如下:
#include <iostream> #include<stdio.h> #include<stdlib.h> using namespace std; int main() { char buf[200]; char c; bool isNext=false; int cnt=0; while((c=getchar())!=EOF){ if(c=='\n'){ cout<<endl; c=getchar(); if(c=='\n') { cout<<endl; isNext=true; } if(c==EOF) break; } if(isNext){ isNext=false; }else{ if(c>='A' && c<='Z' || c=='*'){ for(int i=0;i<cnt;++i) cout<<c; cnt=0; }else if(c=='!'){ cout<<endl; cnt=0; }else if(c=='b'){ for(int i=0;i<cnt;++i) cout<<' '; cnt=0; }else{ cnt+=c-'0'; } } } return 0; }
[/code]
相关文章推荐
- 第五章:基础题目选解。第二部分
- 第二部分面向对像基础第五章下半部分与习题总结
- 算法竞赛入门经典:第五章 基础题目选解 5.12多少块土地
- 《算法竞赛入门经典》 第五章 基础题目选解
- 算法竞赛入门经典:第五章 基础题目选解 5.10 因子和阶乘
- 算法竞赛入门经典:第五章 基础题目选解 5.9 Cantor数
- 第二部分面向对像基础第五章下半部分与习题总结
- 算法竞赛入门经典:第五章 基础题目选解 5.2 Tex
- 算法竞赛入门经典:第五章 基础题目选解 5.1WERTYU
- 算法竞赛入门经典:第五章 基础题目选解 5.11果园里的树
- 算法竞赛入门经典:第五章 基础题目选解 5.6 数组模拟高精度乘法
- 第五章基础题目选解
- 第五章:基础题目选解。第一部分
- 算法竞赛入门经典:第五章 基础题目选解 5.4 小学生算术
- Linux基础学习篇第五章习题
- 算法竞赛入门经典:第五章 基础题目选解 5.8 字母重排
- 经典第五章 习题 5-4 UVA 10763 Foreign Ex(思维题目)
- 第五章:基础题目选解。第二部分
- 算法竞赛入门经典:第五章 基础题目选解 5.5 高精度乘法
- 第五章:基础题目选解。第一部分