I am trying to remove all unique values from a vector. Below is my program output of the vector. The strings that I want to keep in the vector are in the grey box.
ART-105-1129 Spring 2004
FILM-298-1129 Spring 2004
GEOG-298-1370 Spring 2004
MUSLT-110-1370 Spring 2004
BCA-298-1617 Spring 2004
HIST-120-1617 Spring 2004
set<string> s(listOfCourses.begin(), listOfCourses.end());
set<string> dupremove(duplicateTermsAndSections.begin(), duplicateTermsAndSections.end());
for (vector<string>::iterator itouter = duplicateTermsAndSections.begin(); itouter!= duplicateTermsAndSections.end(); itouter++) !copyDuplicateTermsAndSections.empty(); copyDuplicateTermsAndSections.pop())
for (vector<string>::iterator it = listOfCourses.begin(); it != listOfCourses.end(); it++)
if ((*it).find(*itouter) != string::npos)
cout << *it << endl;
cout << endl;
If you compute a frequency map where the keys are your substring you are extracting between the second '-' and the following space. As you iterate over your collection of strings, look at the map. If the key is not yet in the map, put a value of 1 in the map for that key. If the key is in the map, increment the value stored in the map that corresponds to the map.
Then, make a second pass through the collection of strings, if the extracted substring has a corresponding value of 1 in the map, it is unique, otherwise it is a duplicate.
I'll leave it as an exercise for you to work the C++ specific syntax for the above described algorithm.