DNA Sorting
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 95209   Accepted: 38311

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.

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
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT

Sample Output

CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA

C/C++代码

#include <stdio.h>
#include <string.h>
#include <stdlib.h> struct Str{
char str[];
int inversions;
}data[]; int inversionNumber(char s[]) { int len = strlen(s);
int result = ;
int A = , C = , G = ;
int i = len - ;
for(; i >= ; i--)
switch (s[i]) {
case 'A':
A++;
break;
case 'C':
result += A;
C++;
break;
case 'G':
result = result + A + C;
G++;
break;
case 'T':
result = result + A + C + G;
break;
}
return result;
} int cmp(const void * a, const void * b) { struct Str* c = (struct Str *)a;
struct Str* d = (struct Str *)b;
return c->inversions - d->inversions; } int main(int argc, const char * argv[]) { int length, number;
int i;
scanf("%d%d", &length, &number); for (i = ; i < number; i ++) {
scanf("%s", data[i].str);
data[i].inversions = inversionNumber(data[i].str);
} qsort(data, number, sizeof(data[]), cmp); for (i = ; i < number; i ++) {
printf("%s\n", data[i].str);
} return ;
}

poj 1007 DNA sorting (qsort)的更多相关文章

  1. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  2. [POJ 1007] DNA Sorting C++解题

        DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 77786   Accepted: 31201 ...

  3. [POJ] #1007# DNA Sorting : 桶排序

    一. 题目 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95052   Accepted: 382 ...

  4. poj 1007 DNA Sorting

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95437   Accepted: 38399 Des ...

  5. POJ 1007 DNA Sorting(sort函数的使用)

    Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...

  6. POJ 1007 DNA sorting (关于字符串和排序的水题)

    #include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...

  7. poj 1007 DNA Sorting 解题报告

    题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...

  8. poj 107 DNA sorting

    关于Java的题解,也许效率低下,但是能解决不只是ACGT的序列字符串 代码如下: import java.util.*; public class Main { public static void ...

  9. poj 1007 (nyoj 160) DNA Sorting

    点击打开链接 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 75164   Accepted: 30 ...

随机推荐

  1. #ifdef _WIN32的来源

    宏定义:#ifdef _WIN32   由编译器(ml.exe/ml64.exe)内部定义的.具体描述是: _WIN32:Defined for applications for Win32 and ...

  2. LoadRunner脚本编写之二

    LoadRunner脚本编写之二 编程基本语法必须要记牢.程序的思想也很重要. 下面来回顾一下嵌套循环例子. Action() {     int  i,j;   //生命两个变量     for ( ...

  3. python中日志logging模块的性能及多进程详解

    python中日志logging模块的性能及多进程详解 使用Python来写后台任务时,时常需要使用输出日志来记录程序运行的状态,并在发生错误时将错误的详细信息保存下来,以别调试和分析.Python的 ...

  4. C#在非UI线程调用UI线程的控件

    首先需要定义一个委托(delegate): private delegate void delegateSetProcessBarVal(int value); 然后定义一个方法来执行具体的操作: p ...

  5. docker 的安装和镜像

    一.docker的 安装 : 第一种: yum -y install docker systemctl start docker.service systemctl status docker 第二种 ...

  6. python计算机二级考试知识点——文件操作

    1. 文件的使用:文件打开.关闭和读写 python通过open函数打开一个文件,并返回一个操作文件的变量,语法形式如下: <变量名>=open(<文件路劲及文件名>,< ...

  7. HCL试验5

    PC端配置:配置ip地址 交换机1配置:①创建VLAN system-view vlan 10 vlan 20 ②配置PC端接口 interface gi 1/0/1 port link-type a ...

  8. eclipse 建立 web fragment project 工程

    1.鼠标右键---------new ---------Other 2.选择WEB----web fragment project 3.输入工程名,点finish

  9. Emgu 学习(7)threshold ,图像过滤

    Threshold 代码如下 static void Main(String[] args) { Mat img = CvInvoke.Imread(@"C:\Users\dell\Pict ...

  10. SSH代理

    参考: http://www.dkys.org/archives/1111.html SSH的-L与-D代理 SSH有三种代理参数-L,-D,-R.-R代理不是本次重点,有兴趣的读者可以自行查阅man ...