-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.cpp
More file actions
72 lines (61 loc) · 1.79 KB
/
run.cpp
File metadata and controls
72 lines (61 loc) · 1.79 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
71
72
#include <iostream>
#include <vector>
#include "NFA.h"
#include "state.h"
using namespace std;
string input;
vector<bool> answer;
void simulate_input(state *state, int index) {
if (index == (int) (input.size()) + 1)
return;
if (index != 0)
answer[index - 1] = state->is_final() | answer[index - 1];
auto transitions = *state->get_transitions();
for (auto transition: transitions) {
if (transition.first == input[index])
simulate_input(transition.second, index + 1);
}
}
void solve_p2() {
cin >> input;
answer.resize(0);
answer.resize((int) (input.size()), false);
NFA nfa(false);
int num_states, num_finals, num_transitions;
cin >> num_states >> num_finals >> num_transitions;
for (int k = 1; k < num_states; k++) {
state *new_state = new state();
new_state->index = k;
nfa.add_state(new_state);
}
for (int k = 0; k < num_finals; k++) {
int index;
cin >> index;
state *this_state = (*nfa.get_states())[index];
nfa.add_final_state(this_state);
this_state->make_final();
}
for (int k = 0; k < num_states; k++) {
state *this_state = (*nfa.get_states())[k];
int num_t;
cin >> num_t;
for (int i = 0; i < num_t; i++) {
char symbol;
int index;
cin >> symbol >> index;
state *other_state = (*nfa.get_states())[index];
this_state->add_transition({symbol, other_state});
}
}
simulate_input(nfa.get_start_state(), 0);
string answer_to_print = "";
for (auto ans: answer)
if (ans) answer_to_print += 'Y';
else answer_to_print += 'N';
nfa.deep_delete();
cout << answer_to_print << endl;
}
int main() {
solve_p2();
return 0;
}