Poj 1007 DNA sorting (sorting-fast sorting)

Source: Internet
Author: User
DNA sorting
Time limit:1000 ms   Memory limit:10000 K
Total submissions:67603   Accepted:26858

Description

One measure of ''unsortedness ''in a sequence is the number of pairs of entries that are out of order with respect to each other. for instance, in the letter sequence '''daabec'', this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. this measure is called the number of inversions in the sequence. the sequence '''aacedgg ''' has only one inversion (E and D) --- it is nearly sorted --- while the sequence ''zwqm ''has 6 inversions (it is as unsorted as can be --- exactly the reverse of sorted ).

You are responsible for cataloguing a sequence of DNA strings
(Sequences containing only the four letters A, C, G, and T). However,
You want to catalog them, not in alphabetical order, but rather in order
Of ''sortedness '', from ''most sorted'' to ''ast sorted''. All
Strings are of the same length.

Input

The
First line contains two integers: a positive integer N (0 <n <=
50) giving the length of the strings; and a positive integer m (0 <m
<= 100) giving the number of strings. These are followed by M lines,
Each containing a string of length N.

Output

Output
The list of input strings, arranged from ''most sorted'' to ''least
Sorted ''. Since two strings can be equally sorted, then output them
According to the orginal order.

Sample Input

 
10 6 aacatgaaggttttggccaatttggccaaagatcagatttcccggggggaatcgatgcat

Sample output

 
Cccggggggaaacatgaagggatcagatttatcgatgcatttttggccaatttggccaaa

Source

 

# Include <iostream> # Include <Algorithm> Using   Namespace  STD; typedef  Struct  {  String DNA;  Int  Count;} DNA; DNA [  101  ];  Int CMP ( Const   Void *, Const   Void * B) {DNA * AA = (DNA * ) A; DNA * BB = (DNA * ) B;  Return Aa-> count-BB->Count ;}  Int  Main (){  Int  N, m;  Char  C; CIN >>N> M;  For ( Int I = 0 ; I <m; I ++ ) {CIN > DNA [I]. DNA; DNA [I]. Count = 0 ;  For ( Int J = 0 ; J <n; j ++ )  For ( Int K = J + 1 ; K <n; k ++ ){  If (DNA [I]. DNA [J]> DNA [I]. DNA [k]) DNA [I]. Count ++ ;}} Qsort (DNA, m,  Sizeof (DNA [0  ]), CMP );  For ( Int I = 0 ; I <m; I ++ ) Cout <DNA [I]. DNA < Endl;  Return   0  ;} 

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.