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 ...
随机推荐
- PCI总线目标接口状态机设计
module state_machine (devsel_l, trdy_l, stop_l, pci_ad_oe, dts_oe, par_oe, bk_oe, pci_ad_en, hi ...
- 团队博客--测试发布(队名:Running Duck)
代码链接:Tetris 码云地址 一.Alpha版本测试报告 1.测试计划 测试内容 1.方块生成下落 2.方块左右移动 3.方块快速下滑 4.本汉字替换 5.下一个汉字提示 6.方块颜色生成 7.汉 ...
- XML Publisher 并发程序由于"输出提交处理程序提交失败
http://www.cnblogs.com/benio/archive/2012/03/30/2424900.html xmlp 报表运行完成后,状态为warning,其原因大概有以下3类:1.&q ...
- 数据库索引、B树、B+树
数据库索引,是数据库管理系统中一个排序的数据结构,以协助快速查询.更新数据库表中数据.索引的实现通常使用B树及其变种B+树. 在数据之外,数据库系统还维护着满足特定查找算法的数据结构,这些数据结构以某 ...
- jQuery---ajax---error函数及其参数详解
使用jquery的ajax方法向服务器发送请求的时候,常常需要使用到error函数进行错误信息的处理,本文详细说明了ajax中error函数和函数中各个参数的用法. 一般error函数返回的参数有三个 ...
- MariaDB 视图与触发器(11)
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...
- python-i春秋验证码识别
i春秋作家:hlpureboy python+机器学习+验证码识别+源码 简单介绍 最近在写某网站的自动注册,在注册的过程中遇到一些问题,如js的执行.验证码的识别等等,今天给大家如何用python通 ...
- ubuntu16搭建harbor镜像库
参考 https://blog.csdn.net/qq_35720307/article/details/86691752 目的:搭建本地镜像库,方便快速的存放和拉取需要的镜像文件.
- MVC3学习:利用mvc3+ajax实现全选和批量删除
本例数据库操作使用EF code first; 先利用mvc自带的模板,先生成一个list视图,然后再手动添加复选框和删除按钮 <table> <tr> @*在标题行添加一个全 ...
- Python动态变量名定义与调用
动态变量名赋值 在使用tkinter时需要动态生成变量,如动态生成var1...var10变量 使用exec动态赋值 exec在python3中是内置函数,它支持python代码的动态执行. 示例: ...