ACM--字母排序--HDOJ 1379--DNA Sorting--字符串

HDOJ题目地址:传送门

DNA Sorting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 3100    Accepted Submission(s): 1538

Problem 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 ``least sorted‘‘.
All the strings are of the same length.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is 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.

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 (1 < 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‘‘. If two or more strings are equally sorted, list them in the same order they are in the input file.

Sample Input

1

10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

Sample Output

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA

题意: 计算每一个字符串的等级 ,在进行排序  ,等级相同,按原顺序输出

计算等级规则,例如:AACATGAAGG   :

C 大于其后面的 3 个 A ,T 大于其后面的 5 个字符 ,第一个 G 大于其后面的 2 个 A,  字符串等级为  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;
     }

   }
}
时间: 2024-10-11 06:17:47

ACM--字母排序--HDOJ 1379--DNA Sorting--字符串的相关文章

hdoj 1379 DNA Sorting

DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2231    Accepted Submission(s): 1096 Problem Description One measure of ``unsortedness'' in a sequence is the number of pairs of entr

hdu 1379 DNA Sorting

DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1924    Accepted Submission(s): 949 Problem Description One measure of ``unsortedness'' in a sequence is the number of pairs of entrie

HDU 1379 DNA sorting(求逆序数)

DNA Sorting Problem 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 t

Java编程实现中英混合字符串数组按首字母排序的方法

在Java中对于字符串数组的排序,我们可以使用Arrays.sort(String[])方法很便捷的进行排序.例如: ? 1 2 3 4 5 6 7 String[] arrays = new String[] { "gyu", "sdf", "zf", "大同", "收到", "地方", "三等分", "的人", "反对高铁"

DNA Sorting(排序)

欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2182    Accepted Submission(s): 1062 Problem Description One measure of ``unsortedness'' in a sequenc

POJ_1007:DNA Sorting解题报告

[大致题意]排列多个DNA序列,按照每个序列的"有序程度".如果一个序列已经按照字母顺序排好了,那么这个序列有序程度最高,如AACCGGTT.反之,如果一个序列越无序,那么它的有序程度越低,如TGTCAA. [解题思路]计算每个序列的"逆序数",即反序字母对的个数,如ATGC的逆序数是3,因为TG,TC,GC都是逆序的.然后按照每个序列的逆序数排序,逆序数越大说明这个序列越无序. #include <iostream> #include <algo

poj 1007 DNA Sorting (求逆序数)

DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 83069   Accepted: 33428 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 instanc

Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音

转载请注明出处:http://blog.csdn.net/xiaanming/article/details/12684155 前段时间因为换工作的缘故又恰巧碰到国庆节,所以有段时间自己没有更新博客了,过完国庆到新公司报道,感觉还不错,就是现在住的地方离新公司有点远,地铁20站,伤不起啊,我每天早上7点多就要起床,然后屁颠屁颠的去挤地铁上班,晚上下班还要挤地铁,先不说路程远,车费一天就要10几块,我的银子啊,有坐龙华线去上班的深圳程序员不?听说那条线上班高峰期很挤?我没在上班高峰期坐过那趟车,我

字母排序

字母排序 对一行字母进行排序,如:读入一行小写字母,然后将这行字母从a到z进行排序. 首先申请一个字符数组a,然后用gets()进行读入. char a[101];//假设读入的字符不超过100个 gets(a); 接下来我们要知道读入的字符串的长度,可以用strlen()来获取字符串的长度.定义一个整型变量len来存储字符串的长度 int len; len = strlen(a); 说明:如果用了strlen()函数,就需要在程序的最开始引入一个头文件 #include <string.h>