TeX中的引号(UVa272)

 

问题:

在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''.

 

分析:对输入的字符串一个一个字符进行判断,不进行存储

C++11代码如下:

 1 #include<iostream>
 2 using namespace std;
 3 int main() {
 4     int c;  // int型,因为getchar()返回的为int型
 5     bool p = true;
 6     while ((c = getchar()) != EOF) {
 7         if (c == '"') {
 8             cout << (p ? "``" : "''");
 9             p=!p;
10         }
11         else cout << char(c); //输出时转换为字符型
12     }
13     return 0;
14 }
posted on 2018-06-24 20:57  Pink.Pig  阅读(547)  评论(0编辑  收藏  举报