題目描述:
一個DNA序列由A/C/G/T四個字母的排列組合組成。G和C的比例(定義為GC-Ratio)是序列中G和C兩個字母的總的出現次數除以總的字母數目(也就是序列長度)。在基因工程中,這個比例非常重要。因為高的GC-Ratio可能是基因的起始點。給定一個很長的DNA序列,以及要求的最小子序列長度,研究人員經常會需要在其中找出GC-Ratio最高的子序列。
輸入描述:輸入一個string型基因序列,和int型子串的長度輸出描述:找出GC比例最高的字串
輸入例子:
AACTGTGCACGACCTGA
5
輸出例子:GCACG
算法實現:
#include<iostream>#include<vector>#include<string>using namespace std;/************************************************ * Author: 趙志乾 * Date: 2017-2-18 * Declaration: All Rigths Reserved !!! ***********************************************/int main(){ string instr; int len; cin>>instr>>len; int count=0; for(int i=0;i<len;i++) if(instr[i]=='C'||instr[i]=='G') count++; int max=count; int left=0,right=len-1; for(int i=len;i<instr.length();i++) { if(instr[i]=='C'||instr[i]=='G') { count++; } if(instr[i-len]=='C'||instr[i-len]=='G') { count--; } if(count>max) { left=i-len+1; right=i; max=count; } } for(int i=left;i<=right;i++) { cout<<instr[i]; } cout<<endl; return 0;}
新聞熱點
疑難解答
圖片精選