View Problem
From a List Produce a List of Duplicate Entries
Taking a list:
Write the code to produce a list of duplicates in the list:
Submit a new solution for clojure or cpp
There are 18 other solutions in additional languages (csharp, erlang, fantom, fsharp ...)
["andrew", "bob", "chris", "bob"]
Write the code to produce a list of duplicates in the list:
["bob"]
cpp C++0x/C++11 (gcc >=4.6)
vector<string> lst = { "andrew", "bob", "chris", "bob" };
vector<string> lst_no_dups;
vector<string> tmp;
vector<string> dups;
sort(lst.begin(), lst.end());
unique_copy(lst.begin(), lst.end(), back_inserter(lst_no_dups));
set_difference(lst.begin(), lst.end(),
lst_no_dups.begin(), lst_no_dups.end(),
back_inserter(tmp));
unique_copy(tmp.begin(), tmp.end(), back_inserter(dups));
cout << dups << endl;
vector<string> lst_no_dups;
vector<string> tmp;
vector<string> dups;
sort(lst.begin(), lst.end());
unique_copy(lst.begin(), lst.end(), back_inserter(lst_no_dups));
set_difference(lst.begin(), lst.end(),
lst_no_dups.begin(), lst_no_dups.end(),
back_inserter(tmp));
unique_copy(tmp.begin(), tmp.end(), back_inserter(dups));
cout << dups << endl;
Submit a new solution for clojure or cpp
There are 18 other solutions in additional languages (csharp, erlang, fantom, fsharp ...)




