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. Kafka auto.offset.reset

    要从头消费kafka的数据,可以通过以下参数: Kafka auto.offset.reset = earliest

  2. AngularJS $observe $watch

    $observe $watch都可以用来监听值的变化,但是他们有显著的区别.$observe是用来监视DOM属性值的变化,而 $watch监视scope属性值的变化.AngularJS中的监听,都知道 ...

  3. ASP.NET Web API 框架研究 服务容器 ServicesContainer

    ServicesContainer是一个服务的容器,可以理解为—个轻量级的IoC容器,其维护着一个服务接口类型与服务实例之间的映射关系,可以根据服务接口类型获取对应的服务实例.构成ASP.NET We ...

  4. 中科大debian 9 + docker源设置

    wget https://mirrors.ustc.edu.cn/repogen/conf/debian-http-4-stretch -O sources.list sudo apt-get ins ...

  5. node.js fs,http

    error: EventEmitter定义了一个特殊的时间error,它包含了‘错误’的语义,当error被发射时,EventEmitter规定如果没有 响应的监听器,Node.js会把它当做异常,退 ...

  6. ctags的如何生成tags文件

    tags 在使用vim编程和浏览代码是非常有用.可以用CTRL+]和CTRL+t 来回跳转关键字.先生成自己工作目录的tags.最简单粗暴用法: $cd yourwork $ctags -R * 这样 ...

  7. 记录.NET Core在CentOS上基于Jenkins自动化发布

    1.安装Jenkins,我这里采用的是非docker方式安装(两种都行,任选一种) 参考:https://www.cnblogs.com/xiaxiaolu/p/10357806.html https ...

  8. 「PKUSC2018」主斗地(暴搜)

    这道斗地主比 \(PKUWC\) 那道可做多了... 我们用 \(NOIP\) 那道斗地主的思路:暴搜出三代和四代,贪心出散牌. 还有jry为什么要出xx网友而不出他的另一个老婆 我们发现两个人的每回 ...

  9. kafka java.rmi.server.ExportException: Port already in use

    当你在kafka-run-class.sh中添加了export JMX_PORT=9300 开启了 jmx 后, 在使用 kafka bin/目录下的脚本时会报如下错误: java.rmi.serve ...

  10. Vue 项目配置

    配置Vue的app项目首先需要配置本地环境. 1.下载node.js并且安装.(根据自己电脑参数进行选择) 打开cmd,检查是否安装成功. 分别输入: node -v npm -v 结果如图正确显示出 ...