题解 | DNA序列
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int main() {
string s;
int n;
cin >> s >> n;
vector<string> subs;
vector<double> res;
double max = INT_MIN;
for (int i = 0; i < s.length() - n + 1; i++) {
string str;
str = s.substr(i, n);
int count = 0;
for (int j = 0; j < str.length(); j++) {
if (str[j] == 'G' || str[j] == 'C') {
count++;
}
}
res.push_back((double)count / (double)str.length()); //把所有子串和比例都放进去
subs.push_back(str);
}
for (double x : res) { //找到最大值
if(x>max) max = x;
}
int j=-1;
for (int i=0; i<res.size(); i++) { //找到最大值的下标位置
if(res[i] == max) {
j=i;
break;
}
}
cout<<subs[j]; //按照对应关系输出子串
}
// 64 位输出请用 printf("%lld")
