-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsuperstring.cc
More file actions
65 lines (56 loc) · 1.12 KB
/
superstring.cc
File metadata and controls
65 lines (56 loc) · 1.12 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
#include "bottom.hh"
#include "gensufftree.hh"
#include "greedyalgo.hh"
#include "tank.hh"
#include "testsuite.hh"
#include "trace.hh"
#include <exception>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <string.h>
using std::cin;
using std::cout;
using std::endl;
using std::exception;
using std::getline;
using std::string;
void fill_suffix_tree(GenSuffTree &suffix_tree)
{
Tank tank;
string qw;
while (getline(cin, qw)) {
if (!qw.empty()) {
tank.add(qw);
}
}
tank.fill(suffix_tree);
}
int main(int argc, char *argv[])
{
try {
if ((argc == 2) && !strcmp(argv[1], "-t")) {
test_greedy_algo();
return 0;
} else {
GenSuffTree suffix_tree;
fill_suffix_tree(suffix_tree);
// suffix_tree.dump();
TStringIndex n = suffix_tree.get_size();
if (!n) {
TRACE1("no input");
return 0;
} else if (n == 1) {
cout << suffix_tree.get(1) << endl;
return 0;
}
GreedyAlgo algo(n);
cout << algo.compute(suffix_tree) << endl;
return 0;
}
} catch (exception& x) {
TRACE1(x.what());
return -1;
}
}