272 - TEX Quotes

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 and Output

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. 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: ''.

TeX 是一种由Donald Knuth 所发展出的一套文书排版软体。这套软体可以将原始文件档加上一些像字型等型态后,转成一份很漂亮的文件。而一份漂亮的文件是需要用`` 和" 来把别人说的话给「引」出来,而不是用大部份键盘上有的" 。虽然键盘里通常不会有这种有方向的双引号键,不过上面有左单引号` (有人叫backquote ),和右单引号' (有人叫apostrophe 或quote )。你可以在你的键盘上找一下,不过要小心不要将` 与\ ( backslash 键)搞混了。而在TeX 里,使用者可以输入两个左单引号`` 来构成一个左双引号`` ,或者是两个右单引号'' 来构造一个右单引号'' ,不过呢,通常大家打字时都很习惯用普通的双引号" 来引述别人的话。

如果原始文件档内容是:

"To be or not to be," quoth the bard, "that is the question."

则TeX 作出来的文件并不会是我们所想要的:

``To be or not to be," quoth the bard, ``that is the question."

为了要得到上面的文件,我们需要把原始文件变成这个样子:

``To be or not to be,'' quoth the bard, ``that is the question.''

你现在必须要写一个程式,将普通的双引号("),转成有方向性的双引号,而其它文字则不变。而在把普通的双引号换掉的时候,要特别注意,当要开始引述一句话时要用`` ,而结束引述时要用'' 。不用担心会有多层巢状引号的情形,也就是第一个引号一定是用`` 来代替,再来用'' ,然后用`` ,接着用'' ,依此类推。

Input and Output

输入是若干列的文字,其中有偶数个双引号( " ),以end-of-file 做结束。输出的文字必须和输入的一模一样,除了:

每一组双引号的第一个" 必须用两个` 字元(就是`` )来代替
每一组双引号的第二个" 必须用两个' 字元( 就是'')来代替。

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!''
解题思路:符号的转换“"”要看的是全文的,getchar输入,每个单独判断输出。
#include<stdio.h>
int main()
{char a;
int flag=1;
while((a=getchar())!=EOF){
                      if(a=='"'&&flag>0){
                                         printf("``");
                                         flag=0-flag;
                                         }
                      else if(a=='"'&&flag<0){
                                         printf("''");
                                         flag=0-flag;
                                         }
                      if(a!='"')
                      printf("%c",a);
                                              
                      }
return 0;
    }

posted on 2013-02-04 20:22  喂喂还债啦  阅读(1052)  评论(0编辑  收藏  举报