您的位置:首页 > 其它

DNA序列

2015-08-25 20:54 239 查看
找出字符串中G和C,字符个数最多的长度固定的子串

注释:求子串用M.substr(i,j) 从i开始长度为j的子串

点击打开链接

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

int main(){
string dna,temp;
int count = 0,max = 0,n;
cin >> dna>>n;
if (n > dna.size())
return 0;
else{
for (int i = 0; i <= dna.size() - n; i++){
for (int j = 0; j < n; j++){ //计算以i为起点长度为n的子串中,C和G的字符个数。
if (dna.substr(i, n)[j] == 'C' || dna.substr(i, n)[j] == 'G')
count++;
}
if (count>max){
max = count;
temp = dna.substr(i, n);
}
count = 0;
}
}
cout << temp << endl;
system("pause");
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: