/**
* Input: A string Text and an integer k.
* Output: All most frequent k-mers in Text.
*/
#include <iostream> // std::cout, std::endl
#include <string> // std::string
#include <map> // std::map
#include <algorithm> // std::find
using std::map;
using std::string;
using std::find;
using std::cout;
using std::endl;
int main() {
int length = 4;
string input = "ACGTTGCATGTCGCATGATGCATGAGAGCT";
map<string, int> array;
for (int pos = 0; pos < input.length() - length; ++pos) {
string substr = input.substr(pos, length);
auto search = array.find(substr);
// Если строка уже встречалась в тексте
if (search != array.end()) {
search->second += 1;
}else {
array[substr] = 1;
}
}
int max = 0;
for (auto &substr : array) {
if (max < substr.second) {
max = substr.second;
}
}
for (auto &substr : array) {
if (max == substr.second) {
cout << substr.first << " ";
}
}
return 0;
}
Comments
0 B
|👍
/👎