/** * Input: A string Text and an integer k. * Output: All most frequent k-mers in Text. */ #include // std::cout, std::endl #include // std::string #include // std::map #include // 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 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; }