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

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

Source

 
  水题,字符串排序
  题意:给你m个长度为n的字符串,要求让你按照字符串的逆序数进行稳定排序。
    所谓逆序数,就是给定一个排列和一个标准次序,如果这个排列中有两个元素与标准次序不同,则称这是一个逆序,这个排列的所有逆序总数称为这个排列的逆序数。
  思路:定义一个结构体存储字符串和字符串的逆序数,在主程序里,输入字符串之后计算每一个字符串的逆序数。然后用sort进行排序,最后输出排序后的字符串。
  代码

 #include <iostream>
#include <algorithm>
using namespace std;
struct Str{
char s[];
int n; //逆序数个数
};
bool cmp(const Str &a,const Str &b)
{
if(a.n<b.n)
return ;
return ;
}
int main()
{
int n,m,i,j;
Str str[];
while(cin>>n>>m){
for(i=;i<=m;i++) //输入
cin>>str[i].s;
for(i=;i<=m;i++){
int num=;
int A=,C=,G=;
for(j=n-;j>=;j--){
switch(str[i].s[j]){ //计算逆序数
case 'A':A++;break;
case 'C':C++;num+=A;break;
case 'G':G++;num+=A;num+=C;break;
case 'T':num+=A;num+=C;num+=G;break;
default:break;
}
}
str[i].n = num;
}
sort(str+,str+m+,cmp);
for(i=;i<=m;i++)
cout<<str[i].s<<endl;
}
return ;
}

Freecode : www.cnblogs.com/yym2013

poj 1007:DNA Sorting(水题,字符串逆序数排序)的更多相关文章

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

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

  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: 95437   Accepted: 38399 Des ...

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

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

  5. poj 1007 DNA sorting (qsort)

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

  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 1488 Tex Quotes --- 水题

    POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...

  9. poj 2105 IP Address(水题)

    一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...

随机推荐

  1. Java中如何解决double和float精度不准的问题

    我们知道浮点数是无法在计算机中准确表示的,例如0.1在计算机中只是表示成了一个近似值,因此,对付点数的运算时结果具有不可预知性. 在进行数字运算时,如果有double或float类型的浮点数参与计算, ...

  2. spring和hibernate整合时无法自动建表

    在使用spring整合hibernate时候代码如下: <property name="dataSource" ref="dataSource" /> ...

  3. [转载]python gevent

    原地址: http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001407503089 ...

  4. 在win7-64bit环境下,boa-constructor 0.6.1 的palette面板中没有控件图标的解决方法

    在win7-64bit环境下,boa-constructor 0.6.1 的palette面板中没有控件图标,空白一片.将面板窗口拉大,发现那些图标在很下面的位置,X轴的排列与正常状态一致. 软件环境 ...

  5. NGUI研究院之在Unity中使用贝塞尔曲线(六)[转]

    鼎鼎大名的贝塞尔曲线相信大家都耳熟能详.这两天因为工作的原因需要将贝塞尔曲线加在工程中,那么MOMO迅速的研究了一下成果就分享给大家了哦.贝塞尔曲线的原理是由两个点构成的任意角度的曲线,这两个点一个是 ...

  6. pfsense 企业应用实例

    从萌生更换公司网关的想法,到选择.测试.部署陆陆续续用时两个月有余.选择的标准是open and free.这期间不断在查阅一些资料,测试了7.8个各开源防火墙产品.这些产品中大多是基于linux,少 ...

  7. MySQL进程常见的State【转】

    为了查阅方便,做个笔记. 通过show processlist查看MySQL的进程状态,在State列上面的状态有如下这些: Analyzing线程对MyISAM 表的统计信息做分析(例如, ANAL ...

  8. 13.SpringMVC和Spring集成(一) && 14.SpringMVC和Spring集成(二)

    1.概念 Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,Spring致力于J2EE应用的各层的解决方案,Spring是企业应用开发的“一站式”选择,并贯 ...

  9. ABAP 权限程序

    检查用户销售区域与分销渠道的权限     AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'     ID 'VKORG' FIELD wa_all-vkorg     ID 'V ...

  10. Effective C++ -----条款45:运用成员函数模板接受所有兼容类型

    请使用member function templates(成员函数模板)生成”可接受所有兼容类型“的函数. 如果你声明member templates 用于“泛化copy构造”或“泛化assignme ...