题目描述信息较多,但是仔细读完会发现本题所要完成的功能是并不像描述得那么吓人,只是实现给定字符串中指定字符的替换。直接使用string类提供的find_first_of及replace函数就可以解题,具体实现代码如下:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int count = 1;
while(getline(cin, str))
{
string::size_type pos = 0;
while((pos = str.find_first_of("\"", pos)) != string::npos)
{
if(count % 2 == 1)
{
str.replace(pos, 1, "``");
}
else
{
str.replace(pos, 1, "''");
}
++pos;
++count;
}
cout << str << endl;
}
return 0;
}