-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
61 lines (46 loc) · 1.41 KB
/
main.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
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include "filter.h"
using namespace std;
vector<string> split(const string&str, char d){
vector<string> r;
string::size_type start = 0;
string::size_type stop = str.find_first_of(d);
while(stop!=string::npos){
r.push_back(str.substr(start, stop-start));
start = stop+1;
stop = str.find_first_of(d, start);
}
r.push_back(str.substr(start));
return r;
}
int main(int argc, char *argv[])
{
try{
vector<vector<string>> ip_pool;
for(string line; getline(cin, line);){
vector<string> v=split(line, '\t');
ip_pool.push_back(split(v.at(0), '.'));
}
qsort(&ip_pool[0], ip_pool.size(), sizeof(vector<string>), compare);
reverse(ip_pool.begin(), ip_pool.end());
cout<<endl<<"Sorted ip addresses in reverse order"<<endl;
printv(ip_pool);
auto vec = filter(ip_pool,1);
cout<<"TODO filter by first byte and output"<<endl;
printv(vec);
cout<<"TODO filter by first and second bytes and output"<<endl;
auto vec1 = filter(ip_pool, 46, 70);
printv(vec1);
cout<<"TODO filter by any byte and output"<<endl;
auto vec2 = filter_any(ip_pool, 46);
printv(vec2);
}
catch(const exception&e){
cerr<<e.what()<<endl;
}
}