首页 > 代码库 > wfu省赛前练习赛(一)第一题

wfu省赛前练习赛(一)第一题

 

TEX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use “ and ” to delimit quotations, rather than the mundane " which is what is provided by most keyboards. Keyboards typically do not have an oriented double-quote, but they do have a left-single-quote ` and a right-single-quote ‘. Check your keyboard now to locate the left-single-quote key ` (sometimes called the “backquote key”) and the right-single-quote key ‘ (sometimes called the “apostrophe” or just “quote”). Be careful not to confuse the left-single-quote ` with the “backslash” key \. TEX lets the user type two left-single-quotes `` to create a left-double-quote “ and two right-single-quotes ‘‘ to create a right-double-quote ”. Most typists, however, are accustomed to delimiting their quotations with the un-oriented double-quote ". If the source contained "To be or not to be," quoth the bard, "that is the question." then the typeset document produced by TEX would not contain the desired form: “To be or not to be,” quoth the bard, “that is the question.” In order to produce the desired form, the source file must contain the sequence: ``To be or not to be,‘‘ quoth the bard, ``that is the question.‘‘ You are to write a program which converts text containing double-quote (") characters into text that is identical except that double-quotes have been replaced by the two-character sequences required by TEX for delimiting quotations with oriented double-quotes. The double-quote (") characters should be replaced appropriately by either `` if the " opens a quotation and by ‘‘ if the " closes a quotation. Notice that the question of nested quotations does not arise: The first " must be replaced by ``, the next by ‘‘, the next by ``, the next by ‘‘, the next by ``, the next by ‘‘, and so on. Input Input will consist of several lines of text containing an even number of double-quote (") characters. Input is ended with an end-of-file character. Output The text must be output exactly as it was input except that: ? the first " in each pair is replaced by two ` characters: `` and ? the second " in each pair is replaced by two ‘ characters: ‘‘. Sample Input "To be or not to be," quoth the Bard, "that is the question". The programming contestant replied: "I must disagree. To `C‘ or not to `C‘, that is The Question!" Sample Output ``To be or not to be,‘‘ quoth the Bard, ``that is the question‘‘. The programming contestant replied: ``I must disagree. To `C‘ or not to `C‘, that is The Question!‘‘

翻译

TEX是由Donald Knuth开发的排版语言。它需要源文本和几个
排版说明和产生,一个希望,一个美丽的文件。美丽的文件使用“
和“界定报价,而不是普通的”,这是大多数键盘提供的。
键盘通常没有定向双引号,但它们有一个左单引号`和
右单引号“。现在检查您的键盘以找到左单引号键`(有时
称为“反引号键”)和右单引号键(有时称为“撇号”或
只是“报价”)。注意不要混淆左单引号`和“反斜杠”键\。 TEX让
用户类型两个左单引号``创建一个左双引号‘和两个右单引号‘‘
创建右双引号“。然而,大多数打字员习惯于划定报价
与无定向双引号“。
如果源包含
“要成为或不成为,”吟游诗人,“这就是问题。
则TEX生成的排版文档将不包含所需的形式:
“要成为或不成为,”吟游诗人,“这就是问题。
为了生成所需的形式,源文件必须包含以下序列:
“”是或不是,“吟游诗人,”这就是问题。
您将编写一个程序,将包含双引号(“)字符的文本转换为文本
除了双引号已被所需的双字符序列替换外,它们是相同的
由TEX用于使用定向双引号定界引号。双引号(“)字符应该
可以用“`如果”打开引号,“”如果“关闭引号”来适当替换。
请注意,嵌套引用的问题不会出现:第一个“必须由”替换
下一个是“”,下一个是“”,下一个是“”,下一个是“`,下一个是‘‘,依此类推。
输入
输入将包含几行文本,其中包含偶数个双引号(“)字符。
输入以文件结束字符结束。
输出
文本必须与输入完全一样,除了:
?每对中的第一个由两个字符替换:
?每对中的第二个“由两个字符替换:”。
样品输入
“要成为或不成为,”伯德说,“那
是问题“。
编程选手回答说:“我必须不同意。
到“C”或不到“C”,这就是问题!
示例输出
“”是或不是,“”吟游诗人“,”
是问题“。
编程选手回答说:“我必须不同意。
到‘C‘或不到‘C‘,这是问题!‘‘

题解:

看到TEX就想起来紫皮书p47页的原题

这题主要就是条件控制转换符号

当q为真时输出``,否则输出‘‘,运用if语句表达式版a?b:c,只要一行字符串中输出了一次``或‘‘,q=!q,控制只输出一个符号

wfu省赛前练习赛(一)第一题