272-tex Quotes
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=208
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 "and" to delimit quotations, rather than the mundane "which are what is provided by most Keyboa Rds. 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 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 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, ' quoth the Bard, ' this 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 and Output
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. 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! '
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Complete code:
/*0.016s*/
#include <cstdio>
int main (void)
{
char ch;
BOOL op = true;
while (~ (ch = getchar ()))
{
if (ch = = ' \ n ')
putchar (' \ n
'); else if (ch = = "")
{
if (OP)
Putchar (""), Putchar ("");
else
putchar (' \ '), Putchar (' \ ');
op =!op;
}
else
Putchar (CH);
}
}