TEX Quotes Time limit:1000ms Memory limit:10000k Total submissions:10850 accepted:5630
Description 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 Double-left-quote and double-right-quote to delimit quotations, rather than the mundane "which is What is provided by most keyboards. Keyboards typically do not have a 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 "apostrophe" or just "quote"). Be careful confuse the left-single-quote ' "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 with the quotations un-oriented ".
If the source contained
"To Yes or not," quoth the Bard, "which is the question."
Then the typeset document produced by TEX would not contain the desired form: ' To be or ' to ', ' Quoth the Bard, ' that is the question. In order to produce the desired form, the source file must contain the sequence:
' To be, ' and ' Quoth the Bard, ' is the question. '
You are are to write a program which converts text containing Double-quote (") characters into text This is identical except T Hat double-quotes have been replaced by the two-character sequences required by TEX for delimiting quotations with Oriente D double-quotes. The Double-quote (") characters should is replaced appropriately by either ' if ' opens a quotation and by ' if ' "Closes a quotation. Notice that's question of nested quotations does not arise:the a ' must be replaced by ', the next By "," Next by "," Next by "," Next by ", and so on.
Input input would consist of several lines of text containing an even number of double-quote (") characters. The Input is ended with an end-of-file character.
Output the text must be output exactly as it is input except that:
The "the" "in" each pair is replaced by two ' characters: "and
The second "in each pair are replaced by two ' characters: '.
Sample Input
"To Yes or not," quoth the Bard, "This is the
question".
The programming contestant replied: "I must disagree.
" To ' C ' or ' to ' C ', which is the question! '
Sample Output
' To be, ' and ' quoth the ' Bard, ' is ' the
question '.
The programming contestant replied: ' I must disagree.
To ' C ' or ' to ' C ', which is the question! '
Source East, North America 1994
Regionals 1994 >> North America-east-NA
Question Link: POJ1488 UVA272 UVALive5381 TEX quotes.
A brief summary of the question: see above.
Problem Analysis: This is a question about character stream processing, and also a quotation mark conversion problem.
Program Description: In a program, use the flag variable flag to identify the opening or closing quotes.
The C language program for AC is as follows:
/* POJ1488 UVA272 UVALive5381 TEX Quotes *
/#include <stdio.h>
int main (void)
{
int c, flag = 1;
while ((C=getchar ())!= EOF) {
if (c = = ' "') {
if (flag) {
Putchar ('");
Putchar (")";
else {
Putchar (' \ ');
Putchar (' \ ');
}
flag = 1-flag;
} else
Putchar (c);
}
return 0;
}