つづりカードのために、同じ文字が続くところを知りたいです。doubled(word) を書きましょう。前の文字と同じ文字を数えます。coffee は 2、aaa も 2、空の単語は 0 です。
doubled("coffee")→2doubled("cat")→0doubled("book")→1int doubled(const string &word)#include <string>
using namespace std;
int doubled(const string &word) {
int count = 0;
for (int i = 1; i < word.size(); i++) {
// ここにコードを書く:word[i] が前の文字と同じなら count に 1 を足す
}
return count;
}
実行すると例で試せます。よさそうなら提出しましょう。