Huawei Machine Test-dna-string

Source: Internet
Author: User

A DNA sequence consists of an array of a/c/g/t four letters. The ratio of G to C (defined as Gc-ratio) is the total number of occurrences of the G and C two letters in the sequence divided by the total letter count (that is, the sequence length). In genetic engineering, this proportion is very important. Because high Gc-ratio may be the starting point of the gene.

Given a long DNA sequence, and the required length of the least-boy sequence, researchers often need to find the highest-gc-ratio subsequence in it.

Input

Enter a string gene sequence, and the length of the int type substring

Output

Find the most GC-proportional string

Sample input AACTGTGCACGACCTGA 5
Sample output Gcacg
ImportJava.util.Scanner; Public classmain{ Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); String DNA=Scanner.next (); intn=Scanner.nextint ();          System.out.println (Count (dna,n));      Scanner.close (); }              Public StaticString count (String DNA,intN) {intlen=dna.length (); floatmaxratio=0.0f; String maxstring=NULL;  for(inti=0;i<len-n;i++) {String s=dna.substring (i,i+N); floatR=ratio (s); if(r>maxratio) {Maxratio=R; Maxstring=s; }          }          returnmaxstring; }             Public Static floatratio (String s) {intlen=s.length (); intCnt=0;  for(inti=0;i<len;i++)          {              CharC=S.charat (i); if(c== ' G ' | | | c== ' C ') CNT++; }          returncnt*1.0f/Len; }}

Huawei Machine Test-dna-string

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.