[C++] TeX中的引号
题目
在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’’.
分析
本题以回车结束输入。
代码实现
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
getline(cin, str); //接收包含空格的字符串
int n = str.length(), m = 0;
for(int i = 0; i < n; i++)
{
if(str[i] == '"'){
if(m == 0)
cout<<"``";
else
cout<<"''";
m = !m;
}
else
cout<<str[i];
}
return 0;
}