Algorithm contest entry classic examples of quotes 3-1 TeX

Algorithm contest entry classic examples of quotes 3-1 TeX

In TeX, the left double quotation mark is " ”,右双引号是“''”。输入一篇包含双引号的文章,你的任务是 把它转换成TeX的格式。 样例输入: "To be or not to be," quoth the Bard, "that is the question". 样例输出: the To BE or not to BE, '' Quoth at The Bard,` `that IS at The Question ''
key:

  1. How judgment is left or right double quotation marks do not think about the problem that the output end of the line spaces, using a flag variable
  2. How the output string with spaces
    scanf ( "% s", s ) across a space or TAB will stop
  • Use fgetc (fin) to read the file fin an open, read a character, then returns an int
    why the return is int rather than char it? Because if the end of file, fgetc will return a special mark EOF, it is not a char. If the return fgetc (fin) value cast to char, will not be able to separate the ordinary and special EOF character area.
  • If a character is read from the standard input, getchar can be used, which is equivalent to fgetc (stdin).
    Use fgetc (fin) can read a character from an open file in fin. Generally it is not EOF check should then converted to char value
    "fgets (buf, maxn, fin )" read complete row in the character array buf. Buf should ensure sufficient storage of files in a single line.
    getchar () return type int
#include<iostream>
using namespace std;
int main()
{
	int c,q=1;
	//getchar()返回类型 int 
	while((c=getchar())!=EOF)
	{
		if(c=='"') //隐式转换 
		{
			cout<<(q?"``":"''");
			q=!q;
		}
		else cout<<(char)c;
	} 
	return 0;
}

Guess you like

Origin www.cnblogs.com/serendipity-my/p/12635478.html