CF168B.Wizards and Minimal Spell
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's dive into one of the most interesting areas of magic — writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells.
Each spell consists of several lines. The line, whose first non-space character is character "#" is an amplifying line and it is responsible for spell power. The remaining lines are common, and determine the effect of the spell.
You came across the text of some spell. Spell was too long, so you cannot understand its meaning. So you want to make it as short as possible without changing the meaning.
The only way to shorten a spell that you know is the removal of some spaces and line breaks. We know that when it comes to texts of spells, the spaces carry meaning only in the amplifying lines, so we should remove all spaces in other lines. Newlines also do not matter, unless any of the two separated lines is amplifying. Thus, if two consecutive lines are not amplifying, they need to be joined into one (i.e. we should concatenate the second line to the first one). Removing spaces in amplifying lines and concatenating the amplifying lines to anything is forbidden.
Note that empty lines must be processed just like all the others: they must be joined to the adjacent non-amplifying lines, or preserved in the output, if they are surrounded with amplifying lines on both sides (i.e. the line above it, if there is one, is amplifying, and the line below it, if there is one, is amplifying too).
For now those are the only instructions for removing unnecessary characters that you have to follow (oh yes, a newline is a character, too).
The input contains the text of the spell, which should be reduced. Remove the extra characters and print the result to the output.
让我们深入探索魔法中最有趣的领域之一——编写咒语。学习这门既令人兴奋又富有挑战性的学科非常麻烦,因此你现在无需学习那些魔法词汇,只需了解编写咒语的基本规则即可。
每个咒语由若干行组成。若某行的第一个非空格字符为 #,则该行为增幅行(amplifying line),负责决定咒语的威力;其余各行均为普通行(common line),决定咒语的效果。
你偶然发现了一段咒语文本。由于该咒语过长,你无法理解其含义,因此你想在不改变其语义的前提下,将其尽可能缩短。
目前你所知的唯一缩短咒语的方法,是移除部分空格与换行符。我们已知:在咒语文本中,空格仅在增幅行中具有语义,因此应移除所有普通行中的空格;而换行符本身也无语义,除非被其分隔的两行中至少有一行为增幅行。因此,若两个连续的行均非增幅行,则必须将它们合并为一行(即:将第二行直接拼接到第一行末尾)。禁止在增幅行中移除空格,也禁止将增幅行与任何其他行进行拼接。
注意:空行需像其他行一样处理——若其相邻行(上方或下方)存在且均为普通行,则该空行须与这些相邻的普通行合并;若其上下行(若存在)均为增幅行,则该空行必须保留在输出中(即:其上方(若存在)为增幅行,且其下方(若存在)也为增幅行)。
目前,上述即为你必须遵循的、用于移除冗余字符的全部规则(哦,对了,换行符本身也是一种字符)。
输入包含待简化的咒语文本。请移除所有冗余字符,并将结果输出。
输入格式
The input contains multiple lines. All characters in the lines have codes from 32 to 127 (inclusive). Please note that the lines may begin with or end with one or more spaces. The size of the input does not exceed 1048576 ( = 220) bytes. Newlines are included in this size.
In the Windows operating system used on the testing computer, a newline is a sequence of characters with codes #13#10. It is guaranteed that after each line of input there is a newline. In particular, the input ends with a newline. Note that the newline is the end of the line, and not the beginning of the next one.
It is guaranteed that the input contains at least one character other than a newline.
It is recommended to organize the input-output line by line, in this case the newlines will be processed correctly by the language means.
输入包含多行。每行中的所有字符的 ASCII 码均在 32 到 127(含)之间。请注意,每行可能以一个或多个空格开头,也可能以一个或多个空格结尾。输入总大小不超过 1048576( =220)字节。换行符也计入该大小。
在评测机所使用的 Windows 操作系统中,换行符是两个连续字符,其 ASCII 码分别为 #13 和 #10。保证输入中每一行之后都紧跟一个换行符。特别地,整个输入以换行符结尾。注意:该换行符属于当前行的结尾,而非下一行的开头。
保证输入中至少存在一个非换行符的字符。
建议采用逐行方式进行输入与输出;此时,各编程语言自身的机制将能正确处理换行符。
输出格式
Print the text of the spell where all extra characters are deleted. Please note that each output line should be followed by a newline.
Please be careful: your answers will be validated by comparing them to the jury's answer byte-by-byte. So, all spaces and newlines matter.
打印删除所有多余字符后的咒语文本。请注意,每行输出后都应跟一个换行符。
请特别注意:您的答案将通过与裁判组的答案进行字节级比对来验证。因此,所有空格和换行符均需严格匹配。
输入输出样例
输入#1
# include <cstdio> using namespace std; int main ( ){ puts("Hello # World"); # # }输出#1
# include <cstdio> usingnamespacestd;intmain(){puts("Hello#World");# # }输入#2
# #
输出#2
# #
说明/提示
In the first sample the amplifying lines are lines 1 and 7. So, lines 2 to 6 are concatenated to each other, all spaces are deleted from them.
In the second sample the amplifying lines are lines 1 and 3. So, no lines are concatenated to each other.
在第一个样例中,放大行是第 1 行和第 7 行。因此,将第 2 行至第 6 行连接在一起,并删除其中的所有空格。
在第二个样例中,放大行是第 1 行和第 3 行。因此,没有任何行被连接在一起。
输入解题思路,AI测评打分。不知道怎么写?