-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColumnIntersect.cpp
62 lines (43 loc) · 1.22 KB
/
ColumnIntersect.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
using namespace boost;
set<string> BuildColumnSet (ifstream &inf, int column) {
set<string> column_set;
while(inf){
string strInput;
getline(inf, strInput);
if(strInput.length() > 0){
vector<string> vec;
split(vec, strInput, is_any_of("\t"));
column_set.insert(vec[column - 1]);
}
}
return column_set;
}
int main (int argc, char **argv) {
ifstream inf1(argv[1]);
int column1 = atoi(argv[2]);
ifstream inf2(argv[3]);
int column2 = atoi(argv[4]);
set<string> set1 = BuildColumnSet(inf1, column1);
set<string> set2 = BuildColumnSet(inf2, column2);
set<string>::iterator it;
set<string>::iterator it_find;
for(it = set2.begin(); it != set2.end(); ++it){
it_find = set1.find(*it);
if(it_find != set1.end()) cout << (*it) << endl;
}
set1.clear(); set2.clear();
inf1.close(); inf2.close();
return 0;
}