【UVA】 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 thebackquote key") and the right-single-quote key ’ (sometimes called the apostrophe" or justquote"). 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(键盘通常没有定向双引号,但它们有左单引号和右单引号。现在检查你们的键盘,找到左单引号键(有时称为反引号键)和右单引号键’(有时称为撇号或只是引号)。注意不要混淆左单引号和“反斜杠”键。TeX允许用户输入两个左单引号“以创建左双引号”和两个右单引号“以创建右双引号”。) ‘’. Most typists, however, are accustomed to delimiting their quotations with the un-oriented double-quote “.
If the source contained
【UVA】 272 ---	TEX Quotes
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.

【UVA】 272 ---	TEX Quotes

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	char ch;
	int p = 1;
	while ((ch = getchar()) != EOF)
	{
		if (ch == '"')
		{
			if (p)
			{
				cout << "``";
			}
			else
			{
				cout << "''";
			}
			p = !p;
		}
		else
		{
			cout << ch;
		}
	}
	return 0;
}

相关文章: