-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_input.cpp
More file actions
54 lines (45 loc) · 1001 Bytes
/
read_input.cpp
File metadata and controls
54 lines (45 loc) · 1001 Bytes
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
#include "misc.hpp"
#include <fstream>
#include <numeric>
#include <cassert>
void read_input(std::list<InputGraph>& igl, std::istream& is)
{
InputGraph* g = 0;
char line[1024];
while (true)
{
if (! is.getline(line, 1024))
break;
std::vector<std::string> result;
char* p = strtok(line, " \t");
while (p)
{
result.push_back(std::string(p));
p = strtok(0, " \t");
}
if (result.empty())
continue;
if (result[0] == "t")
{
igl.push_back(InputGraph());
g = &igl.back();
g->name = result[2];
}
else if (result[0] == "v")
{
assert(result.size() == 3);
assert(g);
int n = atoi(result[1].c_str());
g->vl[n] = result[2];
}
else if (result[0] == "e")
{
g->edges.push_back(InputGraph::E());
InputGraph::E& e = g->edges.back();
e.from = atoi(result[1].c_str());
e.to = atoi(result[2].c_str());
if (result.size() == 4)
e.el = result[3];
}
}
}