コードは完全に機能しますが、正確にどのように機能するかについて混乱しています。文字列ベクトルを並べ替える必要がある理由がまったくわかりません。単語をアルファベット順に並べ替えるだけですよね?また、文字列変数「Previous」と比較するときに、隣接する単語だけでなく、どの単語をどのように検出できますか
#include <iostream>
#include <vector>
using namespace std;
void detect(vector<string> vs);
int main() {
vector<string> vs;
string current;
while (cin>>current)
vs.push_back(current);
sort(vs.begin(), vs.end());
detect (vs);
system("pause");
}
void detect(vector<string> vs){
string previous = " ";
int index = 0;
while (index < vs.size()) {
if (vs[index]==previous) {
cout<<"repeated words: " <<previous<< endl;
}
previous = vs[index];
index++;
}
}