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. __linux__、__POSIX__宏

    __linux__用于定义linux,__POSIX__不太了解,各系统的宏有如下: std::string getOsName() { #ifdef _WIN32 return "Wind ...

  2. WPF Slider Tickbar 中显示数值

    class CustomTickBar : TickBar { protected override void OnRender(System.Windows.Media.DrawingContext ...

  3. SVN 撤回(回滚)提交的代码

    转: SVN 撤回(回滚)提交的代码 2016年12月20日 17:20:58 怀色 阅读数 68614 标签: svnsvn回滚版本回滚 更多 个人分类: svn   版权声明:本文为博主原创文章, ...

  4. 2019.12.24 【ABAP随笔】smartforms 打印及PDF转化

    冬至已过,又临平安夜和圣诞,又是一年的末尾,闲暇时间需要静下心来温故而知新. 许久未碰打印,知识于脑子又有几分糊涂,遂整理些许知识,记录. 数据随便取于物料表 report Z_smartforms ...

  5. postman插件的安装以及简单介绍

    1:postman是干什么的? Postman官网上这么介绍的:“Modern software is built on APIs,Postman helps you develop APIs fas ...

  6. Postman接口测试:自动获取登录后的cookie并设置环境变量

    在对网站进行接口测试的时候,很多请求往往是需要带登录的cookie才能请求成功的,一般来说,可以用抓包软件(fiddler,浏览器的F12)来查看登录后的cookie,并把它设置到postman的环境 ...

  7. Centos 安装k8s 集群(单master开发环境)

    本教程是在VM中搭建K8s 所以第一步骤先配置虚拟机的ip 和上网情况详细参考https://www.cnblogs.com/chongyao/p/9209527.html 开始搭建K8s集群 两台机 ...

  8. MHA简单部署

    MHA是目前比较成熟的mysql高可用集群方式之一. 一.参考文档:1.官方文档:[ https://github.com/yoshinorim/mha4mysql-manager/wiki ]2.个 ...

  9. [转帖]备忘:CentOS-7 使用systemctl 管理的服务,文件打开数上限1024要改

    备忘:CentOS-7 使用systemctl 管理的服务,文件打开数上限1024要改 https://blog.csdn.net/toontong/article/details/50440272 ...

  10. SQL SERVER 字符串函数 STUFF()

    说明: STUFF 函数将字符串插入到另一个字符串中. 它从第一个字符串的开始位置删除指定长度的字符:然后将第二个字符串插入到第一个字符串的开始位置. 语法: STUFF ( character_ex ...