在TeX中,做双引号是“,右双引号是”。输入一篇包含双引号的文章,输出转换成TeX格式。
输入:"To be or not to be,"quoth the Bard,"that is the question".
输出:“To be or not to be,”quoth the Bard,“that is the question”.
PS:本题的关键是,如何判断一个双引号是左双引号还是右双引号。方法很简单:使用一个标志变量即可。
#include <iostream> #include <cstdio> using namespace std; int main() { int c,q=1; while((c=getchar())!=EOF) { if(c=='"') { printf("%s",q?"“":"”"); q=!q; } else printf("%c",c); } return 0; } //"To be or not to be,"quoth the Bard,"that is the question".