-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcs.cpp
160 lines (142 loc) · 3.89 KB
/
lcs.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* lcs.cpp
*/
#include "./includes/lcs.h"
void LCSLauncher()
{
// welcome menu
cout << " WELCOME TO LCS IMPLEMENTATION " << endl;
cout << " YOU'RE ABLE TO GET LONGEST COMMON SUBSEQUENCES " << endl;
cout << " YOU JUST NEED TO ENTER PATH OF DIFFERENTS " << endl;
cout << " SEQUENCE WITH THE STRUCTURE OF TEXT " << endl;
cout << " LET'S START " << endl;
// GLOBAL MODULE VARIABLES
string s1,s2;
vector<string> sf;
int _lcs;
LCSActionOption(s1,s2,sf,_lcs);
}
bool LCSTryParse(string &input, int &output)
{
try
{
output = stoi(input);
}
catch (invalid_argument)
{
return false;
}
return (output >= 0 && output < 8);
}
void LCSActionMenu()
{
cout << "\n\n HIT THE NUMBER BEHIND THE ACTION TO LAUNCH " << endl;
cout << " 1) LOAD SEQUENCE 1 " << endl;
cout << " 2) LOAD SEQUENCE 2 " << endl;
cout << " 3) PRINT SEQUENCE 1 " << endl;
cout << " 4) PRINT SEQUENCE 2 " << endl;
cout << " 5) LCS(SEQUENCE1,SEQUENCE2) " << endl;
cout << " 6) SAVE RESULT SUBSEQUENCE " << endl;
cout << " 7) PRINT RESULT SUBSEQUENCE " << endl;
cout << " 0) EXIT " << endl;
}
void LCSActionOption(string &s1, string &s2, vector<string> &sf, int &lng)
{
int option = -1;
string action;
vector<vector<cellule> > PD;
do
{
// always show action option to users
LCSActionMenu();
// get users option from command line
// gettng path
do
{
cout << "\n CHOOSE YOUR ACTION " << endl;
action = getInputUser();
// cout << tryParse(action, option) << option << endl;
} while (LCSTryParse(action, option) == false);
// custom action for each action choose
switch (option)
{
case 0:
// Exiting message
cout << " THANKS FOR YOUR RELIABILITY " << endl;
break;
case 1:
// code load 1
LCSReadSequence(s1);
break;
case 2:
// code load 2
LCSReadSequence(s2);
break;
case 3:
// code print 1
cout << "seq1: " << s1 << endl;
break;
case 4:
// code print 2
cout << "seq2: " << s2 << endl;
break;
case 5:
// code lcs
PD = lcs(s1, s2, lng);
#ifdef DEBUG
cout << s1.size() << "," <<s2.size() << endl;
#endif
sf = LCS(s1,s2,PD,s1.size(),s2.size());
#ifdef DEBUG
cout << sf.size() << endl;
#endif
break;
case 6:
// code save result
LCSSaveSequences(sf);
break;
case 7:
// code print result
printSequences(sf, lng);
break;
default:
// code default
break;
}
} while (option != 0);
// Exiting message
}
void LCSReadSequence(string &s)
{
string path;
bool flag = false;
// load first matrix
do
{
// gettng path
do
{
cout << "\n PLEASE HIT THE SEQUENCE PATH " << endl;
path = getInputUser();
} while (path.length() == 0);
flag = readSequence(s, path);
flag ? cout << " PROCESS COMPLETED\n" : cout << " AND ERROR OCCUR\n";
} while (flag == false);
}
void LCSSaveSequences(vector<string> &s)
{
string path;
bool flag = false;
// load first matrix
do
{
// gettng path
do
{
cout << "\n PLEASE HIT THE RESULT LCS PATH " << endl;
path = getInputUser();
} while (path.length() == 0);
flag = writeSequences(s, path);
flag ? cout << " PROCESS COMPLETED\n" : cout << " AND ERROR OCCUR\n";
} while (flag == false);
}