华为机试:DNA序列
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
int main() {
string DNA;
cin >> DNA;
int n;
cin >> n;
int len = DNA.length();
double GC_Ratio = 0;
string ans;
for (int i = 0; i <= len - n; i++) {
string tmp = DNA.substr(i, n);
double temp = ((double)count(tmp.begin(), tmp.end(), 'G') + (double)count(tmp.begin(), tmp.end(), 'C')) / (double)n;
if (GC_Ratio < temp) {
ans = tmp;
GC_Ratio = temp;
}
}
cout << ans << endl;
return 0;
}
查看1道真题和解析
三奇智元机器人科技有限公司公司福利 81人发布