Please explain DNA Sequencing more clearly for me please there's a picture of the decription and also please comment on each line if possible on the code below to for me to have an understanding of what each line is doing. It is in C++. #include #include #include #include using namespace std; set longestCommonSubstring(const string& a, const string& b) { int maxLen = 0; vector > longestSuffix(a.size(), vector(b.size())); set result; for(int i = 0; i < a.size(); ++i) { for(int j = 0; j < b.size(); ++j) { if (a[i] == b[j]) { int ¤t = longestSuffix[i][j]; current = i == 0 || j == 0 ? 1 : longestSuffix[i - 1][j - 1] + 1; int from = i - current + 1; if (current > maxLen) { result.clear(); result.insert(a.substr(from, current)); maxLen = current; } else if (current == maxLen) { result.insert(a.substr(from, current)); } } } } return result; } int main() { string a, b; bool first = true; while(cin >> a >> b) { if (!first) cout << '\n'; else first = false; set result = longestCommonSubstring(a, b); if (result.empty()) cout << "No common sequence."<::const_iterator it = result.begin(); it != result.end(); ++it) cout << *it << '\n'; } } }
Please explain DNA Sequencing more clearly for me please there's a picture of the decription and also please comment on each line if possible on the code below to for me to have an understanding of what each line is doing. It is in C++.
#include <iostream>
#include <string>
#include <
#include <set>
using namespace std;
set<string> longestCommonSubstring(const string& a,
const string& b) {
int maxLen = 0;
vector<vector<int> > longestSuffix(a.size(), vector<int>(b.size()));
set<string> result;
for(int i = 0; i < a.size(); ++i) {
for(int j = 0; j < b.size(); ++j) {
if (a[i] == b[j]) {
int ¤t = longestSuffix[i][j];
current = i == 0 || j == 0 ? 1 :
longestSuffix[i - 1][j - 1] + 1;
int from = i - current + 1;
if (current > maxLen) {
result.clear();
result.insert(a.substr(from, current));
maxLen = current;
} else if (current == maxLen) {
result.insert(a.substr(from, current));
}
}
}
}
return result;
}
int main() {
string a, b;
bool first = true;
while(cin >> a >> b) {
if (!first)
cout << '\n';
else
first = false;
set<string> result = longestCommonSubstring(a, b);
if (result.empty())
cout << "No common sequence."<<endl;
else {
for(set<string>::const_iterator it = result.begin();
it != result.end(); ++it)
cout << *it << '\n';
}
}
}
Step by step
Solved in 2 steps