《算法竞赛入门经典》5.12TeX括号

 1 /*
 2 *在TeX中,左双引号是``,右双引号是''。输入一篇包含双引号的文章,你的任务是把它转换成TeX的格式。
 3 *样例输入:"To be or not to be,"quoth the Bard,"that
 4 *is the question".
 5 *样例输出:``To be or not to be,''quoth the Bard,``that
 6 *is the question''.
 7 */
 8 #include <stdio.h>
 9 
10 int main()
11 {
12     int c, q = 1;
13     while((c = getchar()) != EOF)
14     {
15         if(c == '"') {printf("%s", q ? "``" : "''"); q = !q;}
16         else printf("%c", c);
17     }
18     return 0;
19 }
20 //分析:使用一个标志变量判断一个双引号是左双引号还是右双引号
亲爱的读者:如果觉得本文对你有所帮助,请点击推荐,分享给其他人!
原文地址:https://www.cnblogs.com/zhuangwei/p/5254399.html