POJ 1007 DNA Sorting(sort函数的使用)
Description
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
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
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函数的使用)的更多相关文章
- poj 1007 DNA Sorting
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95437 Accepted: 38399 Des ...
- [POJ 1007] DNA Sorting C++解题
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 77786 Accepted: 31201 ...
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 Des ...
- [POJ] #1007# DNA Sorting : 桶排序
一. 题目 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95052 Accepted: 382 ...
- poj 1007 DNA sorting (qsort)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95209 Accepted: 38311 Des ...
- poj 1007 DNA Sorting 解题报告
题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...
- POJ 1007 DNA sorting (关于字符串和排序的水题)
#include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...
- poj 107 DNA sorting
关于Java的题解,也许效率低下,但是能解决不只是ACGT的序列字符串 代码如下: import java.util.*; public class Main { public static void ...
- poj 1007 (nyoj 160) DNA Sorting
点击打开链接 DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 75164 Accepted: 30 ...
随机推荐
- bootstrap1.1
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...
- Python 高级编程——单例模式
单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. 在 Py ...
- kafka各个版本特点介绍和总结
kafka各个版本特点介绍和总结 1.1 kafka的功能特点: 分布式消息队列 消息队列的数据模型, 形成流式数据. 提供Pub/Sub方式的海量消息处理.以高容错的方式存储海量数据流.保证数据流的 ...
- ipad协议
getLoginQRCode (获取登录二维码)CheckLoginQRCode(检测扫码状态)ManualAuth(扫码登录)ManualAuth(62数据登录)ManualAuth(账号密码登录) ...
- Aspose Word.Dll库自带的bug导致The document appears to be corrupted and cannot be loaded 问题处理。
问题的详细描述: C#在开发过程中使用Aspose.word.dll库去实现word套打功能.但是,最近客户反映出现了一个问题,在打印文档的时候,系统报错.经过定位分析发现是Aspose.word.d ...
- 深入理解Aspnet Core之Identity(5)
主题 本篇我将会介绍验证用户的机制当账户被创建的时候,同样 这个过程主要有IUserValidator这个接口来实现的,和密码验证一样Identity同样也内置已经实现好的账户验证.账户验证的比较简单 ...
- 【问题解决方案】Keras手写数字识别-ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接
参考:台大李宏毅老师视频课程-Keras-Demo 在载入数据阶段报错: ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接 Google之 ...
- Ubuntu系统常见问题解决
我本人使用Ubuntu16.04LTS已经有一段时间了.实话来说,ubuntu虽然确实是开源世界的一款优秀的桌面操作系统,但是易用性和稳定性相比Windows还是差太多.本人从安装系统到逐步配置生产环 ...
- 使用httpClient模拟http请求
在很多场景下都需要用到java代码来发送http请求:如和短信后台接口的数据发送,发送数据到微信后台接口中: 这里以apache下的httpClient类来模拟http请求:以get和Post请求为例 ...
- JQuery 限制文本输入只能输入数字(可自定义正则表达式)
var JVerify = { role: { number: /[0-9\/]/, decimal: /[0-9\.\/]/, code: /[0-9A-Z]/ }, Verify: functio ...