Created
March 7, 2012 07:44
-
-
Save pminkov/1991674 to your computer and use it in GitHub Desktop.
Dedupe - C++ solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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