Problem 001 -- Tex quotes

Source: Internet
Author: User

Problem 001
Texquotes

Tex is a typesetting language developed by Donald knuth. ittakes source text together with a few typesetting instructions andproduces, one hopes, a beautiful document. beautiful users use ''and" 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 keyboard now to locate the left-single-quote key`(Sometimes called the ''backquote key ") and theright-single-quote key'(Sometimes called the ''apostrophe "or just ''quote"). Be careful not to confuse theleft-single-quote`With the ''backslash "Key\. Tex lets the user type two left-single-quotes''To create a left-double-quote ''and tworight-single-quotes''To create a right-double-quote ''. Most typists, however, are accustomed to delimiting theirquotations with the UN-oriented double-quote".

If the source contained

"To be or not to be," Quoth the Bard, "That is thequestion ."

Then the typeset document produced by Tex wocould 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 file mustcontain 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 identicalexcept that double-quotes have been replaced by the two-charactersequences required by Tex for delimiting quotations with orienteddouble-quotes. The double-quote (") Characters shoshould bereplaced appropriately by either''If"Opens a quotation and''If"Closes aquotation. notice that the question of nested quotations does notarise: The first"Must be replaced'', Thenext'', The next'', The next'', The next'', The next'', Andso on.

Input andoutput

Input will consist of several lines of text containing an evennumber of double-quote (") Characters. input is ended withan end-of-file character. The text must be output exactly as it wasinput should t that:

  • The first"In each pair is replaced by two`Characters:''And
  • The second"In each pair is replaced by two'Characters:''.
Sampleinput
"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! ''

Code
# Include
Int main ()
{
Char;
Long int I = 1;
While (A = getchar ())! = EOF)
{
If (A = '"' & I % 2 = 1)
{
Printf ("''");
I ++;
}
Else if (a = '"' & I % 2 = 0)
{
Printf ("''");
I ++;
}
If (! = '"')
Printf ("% C", );

}
Return 0;
}


My way
This is the first question. The first thing to do is to use EOF, which is relatively simple. The difficulty at the beginning of the program is that I don't understand how to get the input from the computer, and I learned how to use getchar after checking the books. Getchar can input a single character for the computer to read. In the middle of the program, it is used to determine whether the input is a pair of quotation marks, and determine the number of quotation marks, and then the symbols required by the corresponding output question. Finally, the return value must be added. In this way, this question is once again obtained by AC, which is truly encouraging!
Later, I heard many people say that this question is super watery, but I would like to say that there are no questions about water, only people with poor levels. You can only start with such a simple question, step by step, and step by step into the program. One day, you will understand the true meaning of programming.
I'm acmer. I'm on my way.

Problem 001 -- Tex quotes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.