acm--Alphabetical Sort--hdoj 1379--dna sorting--string

Source: Internet
Author: User


Hdoj Title Address: Portal



DNA sortingTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 3100 Accepted Submission (s): 1538

Problem descriptionone measure of ' unsortedness ' in a sequence was the number of pairs of entries that was out of order W ith respect to all other. For instance, with the letter sequence "Daabec", this measure is 5, since D was greater than four letters E is greater than one letter to it right. This measure was called the number of inversions in the sequence. The sequence ' AACEDGG ' have only one inversion (E and D)--it are nearly sorted--while the sequence ' ZWQM ' has 6 Inversio NS (it is as unsorted as can be--exactly the reverse of sorted).

You is 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 ' least sorted '. All the strings is of the same length.


This problem contains multiple test cases!

The first line of a multiple input was an integer N and then a blank line followed by N input blocks. Each input block was in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.


Inputthe first line contains, integers:a positive integer n (0 < n <=) giving the length of the strings; and a positive integer m (1 < m <=) giving the number of strings. These is followed by M-lines, each containing a string of length n.

Outputoutput the list of input strings, arranged from "most sorted" to "least sorted". If or more strings is equally sorted, list them in the same order they is in the input file.

Sample Input
6AACATGAAGGTTTTGGCCAATTTGGCCAAAGATCAGATTTCCCGGGGGGAATCGATGCAT

Sample Output
Cccggggggaaacatgaagggatcagatttatcgatgcatttttggccaatttggccaaa

Test instructions: Calculates the rank of each string, sorts, ranks the same, outputs in the original order

Calculate rank rules, for example: Aacatgaagg:

C is greater than 3 a after it, T is greater than 5 characters after it, the first G is greater than 2 a after it, and the string level is 10


 #include <stdio.h> #include <string.h> #include <map> #include <iostream> #include <algorithm>    Using namespace Std;int get (string s) {int result=0;    int temp;            for (int i=0;i<s.size (), i++) {for (int j= (i+1); J<s.size (); j + +) {temp= (s[i]-' 0 ')-(s[j]-' 0 ');            if (temp>0) {result++; }}} return result;   int main () {int t;   cin>>t;   GetChar ();   GetChar ();     while (t--) {map<int,string> ma;     int flag[110];     int n,m;     int index=0;     int temp;     string S;     scanf ("%d%d", &n,&m);     GetChar ();        for (int i=0;i<m;i++) {getline (cin,s);        Temp=get (s);        Ma[temp]=s;     Flag[index++]=temp;     } sort (Flag,flag+index);     int A;        for (int f=0;f<index;f++) {a=flag[f];     cout<<ma[a]<<endl; }   }}




acm--Alphabetical Sort--hdoj 1379--dna sorting--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.