您的位置:首页 > 其它

华为oj初级 DNA序列

2017-03-09 20:55 363 查看
描述

一个DNA序列由A/C/G/T四个字母的排列组合组成。G和C的比例(定义为GC-Ratio)是序列中G和C两个字母的总的出现次数除以总的字母数目(也就是序列长度)。在基因工程中,这个比例非常重要。因为高的GC-Ratio可能是基因的起始点。

给定一个很长的DNA序列,以及要求的最小子序列长度,研究人员经常会需要在其中找出GC-Ratio最高的子序列。

知识点 字符串

运行时间限制 10M

内存限制 128

输入

输入一个string型基因序列,和int型子串的长度

输出

找出GC比例最高的字串

样例输入 AACTGTGCACGACCTGA 5

样例输出 GCACG

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
string s;
getline(cin, s);
int Len;
cin >> Len;
int index;
int num_GC;
int max = 0;
string str;
for (int i = 0; i <=s.size() - Len; i++){
str = s.substr(i, Len);
num_GC = count(str.begin(), str.end(), 'G') + count(str.begin(), str.end(), 'C');
if (num_GC > max){
max = num_GC;
index = i;
}
}
cout << s.substr(index, Len) << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: