题解 | #DNA序列#
DNA序列
https://www.nowcoder.com/practice/e8480ed7501640709354db1cc4ffd42a
#include <iostream> using namespace std; int main() { string to_test; getline(cin, to_test); double len = 0; cin >> len; double rai = -1; double num = 0; int l = 0; int r = 0; for(int i = 0, j = len - 1; j < to_test.size(); i++, j++) { num = 0; for(int k = i; k <= j; k++) { if(to_test[k] == 'C' || to_test[k] == 'G') { num++; } } if((num / len) > rai) { // 浮点数除法 rai = num / len; // 浮点数除法 l = i; r = j; } } cout << to_test.substr(l, len) << endl; return 0; }
注意浮点数除法,可能会出现用整数除得零的情况