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. IEDA 实现自动生成序列化号(serialVersionUID)

    完整操作流程:Setting->Editor->Inspections->Java->Serialization issues->Serializable class w ...

  2. 提升键盘可访问性和AT可访问性

    概述 很多地方比如官网中需要提升 html 的可访问性,我参考 element-ui,总结了一套提升可访问性的方案,记录下来,供以后开发时参考,相信对其他人也有用. 可访问性 可访问性基本上分为 2 ...

  3. python格式化字符串format的用法

    填充与对齐 填充常跟对齐一起使用 ^.<.>分别是居中.左对齐.右对齐,后面带宽度 :号后面带填充的字符,只能是一个字符,不指定的话默认是用空格填充 比如 In [15]: '{:> ...

  4. 动态加载、移除css文件

    修改样式有通过修改class属性来更改,也可以通过动态引入外部的css文件来改变对应的样式展示. 这里就介绍动态引入.移除css文件 ///添加平板样式文件 function loadStyles() ...

  5. Xcode真机报错clang: error: linker command failed with exit code 1 (use -v to see invocation)

    出现这种错误,如下图所示,搜索bitcode,置为NO即可.

  6. 非线性函数图像表示(GLSL)

    说明:绘图区域x轴(0->1),y轴(0->1); 1.y = 0.5 + sqrt(x * (1 - x)) 2.y = smoothstep(a , b , x) y = smooth ...

  7. Jquery(DOM和选择器)

    O(∩_∩)O~~~,今天简单整理了一下最近所学的Jquery知识.下面就总结一下. 首先,对于Jquery我们需要简单了解下: 1.Jquery是开放源代码的JS库, 2.Jquery操作是函数式编 ...

  8. C#编程 XML文档

    XML 指可扩展标记语言,XML 被设计用来传输和存储数据.XML 被设计用来结构化.存储以及传输信息. xml文档展示 <?xml version="1.0" encodi ...

  9. TensorFlow实战第三课(可视化、加速神经网络训练)

    matplotlib可视化 构件图形 用散点图描述真实数据之间的关系(plt.ion()用于连续显示) # plot the real data fig = plt.figure() ax = fig ...

  10. 【Linux开发】彻底释放Linux线程的资源

    Linux系统中程序的线程资源是有限的,表现为对于一个程序其能同时运行的线程数是有限的.而默认的条件下,一个线程结束后,其对应的资源不会被释放,于是,如果在一个程序中,反复建立线程,而线程又默认的退出 ...