In: Computer Science
Description:
In this assignment, you will implement a deterministic finite automata (DFA) using C++ programming language to extract all matching patterns (substrings) from a given input DNA sequence string.
Note: even if the same pattern is found multiple times, it should be printed every time it is found. The program should mimic how a DFA processes a string: reading one letter at a time and doing state transitions. Don’t directly check if the string begins with ‘A’ and end with ‘T’.
Below are two sample input/output. Only the bolded are user input.
Input a DNA sequence: CATTTGCAGGTG
Matching patterns are:
AT
ATT
ATTT
ATTTGCAGGT
AGGT
Input a DNA sequence: TTTATAAAA
Matching patterns are:
AT
What to submit:
A zipped file containing the following:
(a) DFA
q0- initial state
q2- final state
(b) Code
#include
<bits/stdc++.h>
using namespace
std;
set<string> s2;
void func(string
stri)
{
for (int i =
0; i < stri.length(); i++)
{
if (stri[i]=='A')
{
for (int j = i; j <
stri.length(); j++)
{
if
(stri[j]=='T')
{
string s = stri.substr(i, j);
s2.insert(s);
}
}
}
}
}
int main()
{
string s =
"CATTT";
func(s);
for (auto i
: s2)
cout << i << " ";
cout <<
endl;
return
0;
}
Output