#include <iostream> #include <vector> #include <list> std::list<std::string> getTotalEntrollment(std::vector<std::list<std::string>> courseStudent, std::list<std::string> dropStudent) { std::list<std::string> allStudent; for(auto &list : courseStudent) { allStudent.insert(std::end(allStudent),std::begin(list),std::end(list)); } allStudent.sort(); //升序排列 allStudent.unique(); //去除重复的std::stirng name for(auto &it : dropStudent) { allStudent.remove(it); //去除在courseStudent中出现的dropStudent中的元素,注意这里不能用erase()方法 } return allStudent; } int main() { std::list<std::string> list_1; std::list<std::string> list_2; std::list<std::string> list_3; std::vector<std::list<std::string>> vecList; std::list<std::string> resultList; std::list<std::string> dropList; list_1.push_back("abc"); list_1.push_back("bcd"); list_1.push_back("cde"); list_2.push_back("dnd"); list_2.push_back("skd"); list_2.push_back("dnd"); list_3.push_back("213"); list_3.push_back("424"); list_3.push_back("424"); dropList.push_back("abc"); dropList.push_back("dnd"); vecList.push_back(list_1); vecList.push_back(list_2); vecList.push_back(list_3); resultList = getTotalEntrollment(vecList,dropList); for(auto it : resultList) { std::cout << it << std::endl; } return 0; }
结果是:
213
424
bcd
cde
skd