WFU A

来源:互联网 发布:温哥华华人 知乎 编辑:程序博客网 时间:2024/05/21 09:10

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题

运用if语句表达式版a?b:c,a为真时值为b,否则为c

#include<stdio.h>
int main()
{
int c,q=1;
while((c=getchar())!=EOF)
{
if(c=='"')
{
printf("%s",q?"``":"''");//当q为1时输出``否则''
q=!q;//第一次检测完q=-1,后输出第二个
}
else
printf("%c",c);
}
return 0;
}

0 0
原创粉丝点击