-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
122 lines (94 loc) · 2.39 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <algorithm>
#include <iostream>
#include <iterator>
#include <fstream>
#include "re_compnent/_re_component.hpp"
#include "vertexes/_vertex_with_e.hpp"
#include "state_machine/memory_optimisation/state_machine_slow.hpp"
#include "state_machine/time_optimisation/state_machine_fast.hpp"
constexpr size_t _alphabet_size = 40;
size_t symbol_caster(const char c)
{
if (c == ' ')
{
return 0;
}
if ('0' <= c && c <= '9')
{
return c - '0' + 28u;
}
if (c == ',')
{
return 38;
}
if (c == '.')
{
return 39;
}
if ('a' <= c && c <= 'z')
{
return c - 'a' + 1u;
}
return c - 'A' + 1u;
}
using re = _re_component<_alphabet_size, symbol_caster>;
using sm = state_machine_slow<_alphabet_size, symbol_caster>;
using smf = state_machine_fast<_alphabet_size, symbol_caster>;
using sms = state_machine_suf<_alphabet_size, symbol_caster>;
re generate_article_searcher()
{
re digit(re("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"), '+');
re digit_and_after_space(digit, re(re(","), '?'), re(" ", "."));
return re(re("article ", "articles ", "arts "), re(digit_and_after_space, '+'));
}
std::string read_file(const std::string& file_name)
{
std::ifstream in(file_name);
std::string buffer;
if (in.is_open())
{
std::string tmp;
while (in >> tmp)
{
buffer += tmp + " ";
}
}
else
{
std::cout << "No input file.\n";
return "";
}
return buffer;
}
// current version - fast compilation, slow execution.
int main()
{
/*
setlocale(LC_ALL, "rus");
auto buffer = read_file("../input.txt");
re _re_component = generate_article_searcher();
sm machine(_re_component);
if(!buffer.empty())
{
std::cout << buffer << '\n';
const auto result = machine.find_end_positions(buffer);
for(const auto& elem:result)
{
std::cout << elem << ' ';
}
}
*/
re block(re("a", "b"), '+');
re rblock(re("a", "b"), '+');
// block = re(re(re(re("a"),'*'),re(re("a"),'*')), '+');
smf machine(block, rblock);
std::cout<<block.size()<<' '<<machine.size()<<'\n';
machine.print();
auto result = machine.find_end_positions("abacaba");
for(const auto& elem:result)
{
std::cout << elem << ' ';
}
return 0;
}
// ababababa