题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
#include <iostream> using namespace std; #include <string> int main() { string str; int len; getline(cin, str); cin >> len; int max = 0; string maxStr; for (int i = 0; i + len <=str.size(); i++) { string temp = string(str.begin() + i, str.begin() + i + len); int tempMax = 0; for (int j = 0; j < len ; j++) { if(temp[j] == 'C' || temp[j] == 'G'){ tempMax++; } } if(tempMax > max){ maxStr = temp; max = tempMax; } } cout << maxStr << endl; }
要注意考虑全长的情况
暴力搜索算法
华为机试刷题记录 文章被收录于专栏
记录一下手打代码的解题思路方便复习