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
 /*
问题 输入每个字符串的长度n和字符串的个数,计算并将这些字符串的按照它的逆序数排序输出
解题思路 将一个字符串和它的逆序数存入一个结构体数组中,使用sort按照逆序数排序输出即可。
*/
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; struct Dstr{
string str;
int cou;
}Dstrs[];
int unsortnum(char *str); bool cmp(struct Dstr a,struct Dstr b){
return a.cou<b.cou;
} int main()
{
int i,n,m;
char temp[];
while(scanf("%d%d",&n,&m) != EOF){
for(i=;i<m;i++){
scanf("%s",&temp);
Dstrs[i].str=temp;
Dstrs[i].cou=unsortnum(temp);
} sort(Dstrs,Dstrs+m,cmp); for(i=;i<m;i++){
printf(Dstrs[i].str.c_str());
printf("\n");
}
}
return ;
} int unsortnum(char *str){
int len=strlen(str),i,j,un=;
for(i=;i<len-;i++){
for(j=i+;j<len;j++){
if(str[i] > str[j]) un++;
}
}
//printf("%s %d\n",str,un);
return un;
}

POJ 1007 DNA Sorting(sort函数的使用)的更多相关文章

  1. poj 1007 DNA Sorting

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95437   Accepted: 38399 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: 80832   Accepted: 32533 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 解题报告

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

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

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

  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. Ubuntu12.04 root用户登录设置

    ubuntu12.04默认是不允许root登录的,在登录窗口只能看到普通用户和访客登录.以普通身份登录Ubuntu后我们需要做一些修改. 1.普通用户登录后,修改系统配置文件需要切换到超级用户模式,在 ...

  2. 调试 .NET Framework 源代码、.DotNetCore源码

    调试 .NET Framework 源代码..DotNetCore源码 如何调试 .NET Framework 源代码 在 Visual Studio 调试器中指定符号 (.pdb) 和源文件 .NE ...

  3. 为什么主流的 App 看起来都差不多?这可能是件好事

    欢迎访问网易云社区,了解更多网易技术产品运营经验. 现在设计师可以把精力都花在真正有意义的地方了. 打开Instagram.Airbnb.Apple Music.Twitter.Dropbox或Lyf ...

  4. Spring IOC 容器源码分析 - 创建单例 bean 的过程

    1. 简介 在上一篇文章中,我比较详细的分析了获取 bean 的方法,也就是getBean(String)的实现逻辑.对于已实例化好的单例 bean,getBean(String) 方法并不会再一次去 ...

  5. file-loader引起的html-webpack-plugin坑

    引言 最近,我们的一个后台系统要改版为基于react + redux + react-router + ant-design 技术栈,切换到当下比较新的技术来实现后台系统:在项目实施过程中,选择了基于 ...

  6. 基于tkinter的九型人格测试系统介绍

    基于tkinter的九型人格测试系统介绍 一.程序代码地址,GitHub 二.程序介绍 1.login.py 登录界面: 注册界面: 2.mainWindow.py 登录成功之后的界面: 3.doTe ...

  7. spring cloud学习(三) 断路器

    在Spring Cloud中使用了Hystrix 来实现断路器的功能.Hystrix是Netflix开源的微服务框架套件之一,该框架目标在于通过控制那些访问远程系统.服务和第三方库的节点,从而对延迟和 ...

  8. Spring Boot中使用@Async实现异步调用

    在Spring Boot中,我们只需要通过使用@Async注解就能简单的将原来的同步函数变为异步函数,为了让@Async注解能够生效,还需要在Spring Boot的主程序中配置@EnableAsyn ...

  9. <c:if test=""></c:if>如何判断空(使用例子)

    <c:if test=""></c:if>如何判断空(使用例子) 标签: session / 前端 / c-if userName是登录的时候放到sessi ...

  10. 记录cacl()函数中使用scss变量不生效的问题

    问题 使用cacl()动态计算元素的高度,运算中包含一个scss变量.如下: height: calc(100% - $ws-header-height); 在浏览器中发现并没有达到预期效果,scss ...