この問題の C++ コードを書きました。問題は基本的に、オープニング"
をに置き換え``
、クロージング"
をに置き換えること''
です。
それは非常に簡単ですが、私は間違った答えを得ています。誰かが私のコードの問題を見つけるのを手伝ってくれますか?
サンプル入力:
"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"
出力例:
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''
コード:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main(){
string inputString;
while (getline(cin, inputString)){
int nDoubleQuotes = 0;
for (int i = 0 ; i < (int)inputString.length(); ++i){
if (inputString[i] == '"'){
++nDoubleQuotes;
nDoubleQuotes = nDoubleQuotes%2;
if (nDoubleQuotes == 1)
cout << "``";
else
cout << "''";
}
else
cout << inputString[i];
}
cout << '\n';
inputString.clear();
}
return 0;
}