我有一个包含5个名为bottledNotes的元素的字符串向量。我试图在一个名为products的vector类中找到它,里面有一个名为productNames的字符串向量,bottledNotes的哪些元素在每个产品的productNames中。
理想情况下,我想在重复方面对结果进行排序。意思是,如果瓶装注意重复5次,那么请将该产品退回给我。这是我的第一个方法:
vector <Products> ofApp::returnProductsSuggestions(vector<Products> &_notesProducts, vector<string> &_bottledNotes){
vector<Products> newProducts;
for( int i = 0; i < _notesProducts.size(); i++){
// cout << "We made it into to the products" << endl;
for( int j = 0; j < _notesProducts[i].productNotes.size(); j++){
// cout << "We made it into to the productNotes" << endl;
for ( int k = 0; k < _bottledNotes.size(); k++){
if( five of the bottleNotes are repeated in the productNotes){
newProducts.push_back(_notesProducts[i]);
}
if( four of the bottleNotes are repeated in the productNotes){
newProducts.push_back(_notesProducts[i]);
}
//etc...
if ( _notesProducts[i].productNotes[j] == _bottledNotes[k] && i == 0){// we chec in the first set of products
// cout << "These are the notes that are included in the first product: " << _bottledNotes[k] << endl;
break; }
}
}
}
return _notesProducts;
}
有这种方法可以做到这一点吗?我愿意接受建议。