题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
// 暴力解法
#include <iostream>
using namespace std;
int main() {
string str;
int n;
cin >> str >>n;
string subStr, ans;
int cnt = 0;
int len = str.length();
if(len == n){
ans = str;
}else{
int maxCnt = 0;
for(int i = 0; i < len - n; ++i){
subStr = "";
cnt = 0;
for(int j = i; j < i+n; j++){
if(str[j] == 'C' || str[j] == 'G'){
cnt++;
}
subStr += str[j];
}
if(cnt > maxCnt){
maxCnt = cnt;
ans = subStr;
}
}
}
cout << ans << endl;
}
// 64 位输出请用 printf("%lld")
查看7道真题和解析