-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (51 loc) · 1.43 KB
/
Copy pathmain.cpp
File metadata and controls
70 lines (51 loc) · 1.43 KB
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
63
64
65
66
67
68
69
70
#include <fstream>
#include <sstream>
#include "include/graph.hpp"
using namespace std;
const string REFERENCE = "https://github.com/prokls/edmonds-branching-algorithm/blob/master/haskell/edmonds.hs";
const string FILE_NAME = "examples/graph4.txt";
vector<string> remove_empty_lines(const vector<string> lines) {
vector<string> ls;
for(const string& line : lines) {
bool b = true;
for(const char& c : line) {
b = b && isspace(c);
}
if(!b) {
ls.push_back(line);
}
}
return ls;
}
vector<string> remove_comments(const vector<string> lines) {
vector<string> ls;
for(const string& line : lines) {
size_t i = line.find('#');
if(i != string::npos) {
ls.push_back(line.substr(0, i));
} else {
ls.push_back(line);
}
}
return remove_empty_lines(ls);
}
vector<string> read_lines() {
vector<string> lines;
string line;
ifstream input_file(FILE_NAME);
if(!input_file.is_open()) {
cerr << "Error: Unable to open file `" << FILE_NAME << "`" << endl;
exit(EXIT_FAILURE);
}
while(getline(input_file, line)) lines.push_back(line);
input_file.close();
return remove_comments(lines);
}
int main() {
Graph* g = new Graph(read_lines());
cout << g->str() << endl;
Graph arb = Graph::edmonds(*g);
cout << arb.str() << endl;
delete g;
return 0;
}