"OJ" "Algorithm Total chapter" "OJ" "089-dna series" "Project Download" topic description
一个DNA序列由A/C/G/T四个字母的排列组合组成。G和C的比例(定义为GC-Ratio)是序列中G和C两个字母的总的出现次数除以总的字母数目(也就是序列长度)。在基因工程中,这个比例非常重要。因为高的GC-Ratio可能是基因的起始点。给定一个很长的DNA序列,以及要求的最小子序列长度,研究人员经常会需要在其中找出GC-Ratio最高的子序列。
Enter a description
输入一个string型基因序列,和int型子串的长度
Output description
找出GC比例最高的字串
Input example
AACTGTGCACGACCTGA5
Output example
GCACG
Algorithm implementation
ImportJava.util.Scanner;/** * Author: Wang Junshu * date:2016-01-06 15:18 * All rights Reserved!!! */ Public class Main { Public Static void Main(string[] args) {Scanner Scanner =NewScanner (system.in);//Scanner Scanner = new Scanner (Main.class.getClassLoader (). getResourceAsStream ("Data.txt")); while(Scanner.hasnext ()) {String input = Scanner.nextline ();intn = scanner.nextint (); SYSTEM.OUT.PRINTLN (Maxratio (input, n)); } scanner.close (); }/** * Initializes two arrays, a sequence of Valarray k[n], a sequence and an array of sum[n], first traversing the side sequence, * C or G for k[i] 1, otherwise set to 0, then calculates the sum of successive M-k[i] and sums the rows. * * @param S * @param m * @return */ Private StaticStringMaxratio(String S,intm) {int[] k =New int[S.length ()];int[] sum =New int[S.length ()]; for(inti =0; I < s.length (); i++) {Charc = S.charat (i);if(c = =' C '|| c = =' G ') {k[i]++; } } for(inti =0; i < k.length-m; i++) { for(intj =0; J < M; J + +) {Sum[i] + = K[i + j]; } }intMax =0;intIDX =0; for(inti =0; I < k.length-1; i++) {if(Sum[i] > Max) {max = sum[i]; idx = i; } }returnS.substring (idx, IDX + m); }}
"OJ" "089-dna sequence"