C++ での文字列操作に問題があります。
ルール: 文章や段落で同じ「単語」が繰り返される場合は、整数にする必要があります。
例:
- 入力:
we prefer questions that can be answered, not just we discussed that.
- 出力:
1 prefer questions 2 can be answered, not just 1 discussed 2.
1 we
2 that
C++ での文字列操作に問題があります。
ルール: 文章や段落で同じ「単語」が繰り返される場合は、整数にする必要があります。
例:
we prefer questions that can be answered, not just we discussed that.
1 prefer questions 2 can be answered, not just 1 discussed 2.
1 we
2 that
この種の問題は、連想配列を使用して既に見た単語を追跡すると、通常ははるかに簡単に解決できます。STL マップを使用して、既に見た単語を保存してみてください。ロジックを正しく設定するには多少の作業が必要ですが、マップは間違いなくあなたがやろうとしていることを助けてくれます。
これは私がとるアプローチです(宿題なのでアルゴリズムのみ)。