Skip to content

Instantly share code, notes, and snippets.

@pminkov
Created March 7, 2012 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pminkov/1991674 to your computer and use it in GitHub Desktop.
Save pminkov/1991674 to your computer and use it in GitHub Desktop.
Dedupe - C++ solution
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
int main() {
int aa[3] = {1, 2, 5};
int bb[5] = {6, 5, 1, 7, 5};
int cc[4] = {2, 8, 16, 8};
vector<int> a(aa, aa + SIZE(aa));
vector<int> b(bb, bb + SIZE(bb));
vector<int> c(cc, cc + SIZE(cc));
vector<vector<int> > all;
all.push_back(a);
all.push_back(b);
all.push_back(c);
vector<vector<int> > nodups;
set<int> seen;
for (int vi = 0; vi < all.size(); ++vi) {
nodups.push_back(vector<int>());
for (int i = 0; i < all[vi].size(); ++i) {
int val = all[vi][i];
if (!seen.count(val)) {
nodups.back().push_back(val);
seen.insert(val);
}
}
}
for (int vi = 0; vi < nodups.size(); ++vi) {
cout << "list:";
for (int i = 0; i < nodups[vi].size(); ++i) {
if (i) cout << ",";
cout << nodups[vi][i];
}
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment