poj1488(字符串处理)

来源:互联网 发布:什么是淘宝同步单 编辑:程序博客网 时间:2024/06/03 18:18

http://poj.org/problem?id=1488

TEX Quotes
Time Limit: 1000MSMemory Limit: 10000KTotal Submissions: 7419Accepted: 3901

Description

TEX is a typesettinglanguage developed by Donald Knuth. It takes source text togetherwith a few typesetting instructions and produces, one hopes, abeautiful document. Beautiful documents use double-left-quote anddouble-right-quote to delimit quotations, rather than the mundane "which is what is provided by most keyboards. Keyboards typically donot have an oriented double-quote, but they do have aleft-single-quote ` and a right-single-quote '. Check your keyboardnow to locate the left-single-quote key ` (sometimes called the"backquote key") and the right-single-quote key ' (sometimes calledthe "apostrophe" or just "quote"). Be careful not to confuse theleft-single-quote ` with the "backslash" key \. TEX lets the usertype two left-single-quotes `` to create a left-double-quote andtwo right-single-quotes '' to create a right-double-quote. Mosttypists, however, are accustomed to delimiting their quotationswith 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 thedesired form: "To be or not to be," quoth the bard, "that is thequestion." In order to produce the desired form, the source filemust contain the sequence:
``To be or not to be,'' quoth the bard, ``that is thequestion.''
You are to write a program which converts text containingdouble-quote (") characters into text that is identical except thatdouble-quotes have been replaced by the two-character sequencesrequired by TEX for delimiting quotations with orienteddouble-quotes. The double-quote (") characters should be replacedappropriately by either `` if the " opens a quotation and by '' ifthe " closes a quotation. Notice that the question of nestedquotations does not arise: The first " must be replaced by ``, thenext by '', the next by ``, the next by '', the next by ``, thenext by '', and so on.

Input

Input will consistof 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 beoutput 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, "thatis 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, ``thatis the question''.The programming contestant replied: ``I must disagree.To `C' or not to `C', that is The Question!''

Source

East Central North America 1994
这题白书上有原题原解,我就不说废话了。
参照白书70页。。
#include<stdio.h>
int main()
{
 int c,q=1;
 while((c=getchar())!=EOF)
 {
  if(c=='"')
  {
   printf("%s",q?"``":"''");
   q=!q;
  }
  else
   printf("%c",c);
 }
 return 0;
}
原创粉丝点击