-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule.cpp
65 lines (63 loc) · 1.25 KB
/
rule.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
#include<string>
#include<vector>
#include "rule.h"
#include <iostream>
#include <algorithm>
rule::rule(string s1, string s2) {
r_l.push_back(s1);
r_r.push_back(s2);
len++;
}
void rule::show() {
for (int i = 0; i < len; i++) {
std::cout << r_l[i] << " -> " << r_r[i] << std::endl;
}
}
void rule::back_rule() {
if (len == 1) {
string templ = r_l[0];
string tempr = r_r[0];
r_l.pop_back();
r_r.pop_back();
len--;
if (tempr =="@") {
r_l.push_back(templ);
r_r.push_back(".");
len++;
return;
}
else {
for (int i = 0; i <= tempr.length(); i++) {
string temp_l;
string temp_r;
for (int j = 0; j < i; j++) {
temp_l.push_back(tempr[j]);
}
for (int j = i; j < tempr.length(); j++) {
temp_r.push_back(tempr[j]);
}
string a = temp_l + "." + temp_r;
r_l.push_back(templ);
r_r.push_back(a);
len++;
}
}
}
}
bool rule::operator==(const rule b) {
int flag = 1;
if (len != b.len) {
return false;
}
for (int i = 0; i < len; i++) {
string templ = r_l[i];
string tempr = r_r[i];
auto it_l = find(b.r_l.begin(), b.r_l.end(), templ);
auto it_r = find(b.r_r.begin(), b.r_r.end(), tempr);
if (it_l == b.r_l.end() || it_r==b.r_r.end()) {
flag = 0;
break;
}
}
return flag == 1 ? 1 : 0;
}