"OJ" "089-dna sequence"

Source: Internet
Author: User


"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"


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.