题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
//暴力的代码
//主要想吐槽一下题目里说的“DNA序列为 ACGT 的子串有: ACG , CG , CGT 等等,但是没有 AGT , CT 等等”
//我判断了半天没有AGT、CT、ACT等等情况,难怪一个用例都过不了...
#include <iostream>
#include <string>
using namespace std;int main() {
string inputstr;
cin >> inputstr;
int len;
cin >> len;
double maxratio = 0;
string res;
for(int i = 0;i<=inputstr.size()-len;++i){
double countCG = 0.0;
string strtmp;
for(int j = i;j<i+len;++j){
strtmp += inputstr[j];
if(inputstr[j] == 'C' || inputstr[j] == 'G')++countCG;
}
if(strtmp.size() == len && (countCG/len > maxratio)){
maxratio = countCG/len;
res = strtmp;
}
}
cout << res << endl;
return 0;
}