poj 1007 (nyoj 160) DNA Sorting
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 75164 | Accepted: 30115 |
Description
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
Output
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA
把每个序列的逆序数求出来然后根据逆序数稳定排序后升序输出,注意qsort中cmp函数的使用,当a == b时返回0则不处理两个数
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<string>
using namespace std;
typedef struct NODE
{
int num;
string str;
}Node; int comp(const void* a,const void* b)
{
Node* x=(Node*)a;
Node* y=(Node*)b;
return (x->num)-(y->num);
}
int main()
{
int n, m;
Node array[101];
while(cin>>n>>m)
{
int i;
for(i = 0; i < m; i++)
{
Node node;
cin>>node.str;
int j;
int count = 0;
int len = node.str.length();
for(j = 0; j < len - 1; j++)
{
int k;
if(node.str[j] == 'A')
continue;
for(k = j + 1; k < len; k++)
{
if(node.str[j] > node.str[k])
count ++;
}
}
node.num = count;
array[i] = node;
}
qsort(array, m, sizeof(Node), comp);
for(i = 0; i < m; i++)
cout<<array[i].str<<endl; }
return 0;
}
poj 1007 (nyoj 160) DNA Sorting的更多相关文章
- [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
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95437 Accepted: 38399 Des ...
- DNA Sorting POJ - 1007
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 114211 Accepted: 45704 De ...
- poj 1007 DNA sorting (qsort)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95209 Accepted: 38311 Des ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
- 算法:POJ1007 DNA sorting
这题比较简单,重点应该在如何减少循环次数. package practice; import java.io.BufferedInputStream; import java.util.Map; im ...
- [POJ1007]DNA Sorting
[POJ1007]DNA Sorting 试题描述 One measure of ``unsortedness'' in a sequence is the number of pairs of en ...
随机推荐
- 重新加载maven项目的依赖项
最近在调试reportNG,测试允许完以后,报告总是使用的testNG的格式,并且只有index和overview两个文件. 找了好多帖子,大家都是那么设置的都没有问题,难道是哥人品不好?错! 大家基 ...
- PYTHON错误代码及解决办法
(1)用sklearn进行逻辑回归时,建立完模型,由于要预测的数据量很大,无法一次全部预测,只能每次预测一个样本数据, 在每次以列表形式输入数据进行预测时出现: /Users/donganlan/an ...
- ASP.NET MVC 控制器向View传值的三种方法
转自:http://www.cnblogs.com/shinima/p/3940452.html 1.提供视图模型对象 你能把一个对象作为View方法的参数传递给视图. public ViewResu ...
- 编译工程时报illegal character:\65279--转
windows对UTF-8文件进行了特殊处理,对UTF-8的文本文件自动在前面加了三个byte(EF BB BF),javac编译时,读到最前面这三个byte时报错 illegal character ...
- 配置Windows Server2008+iis+php+mysql所需下载安装包
最近一个朋友让我帮忙给配置服务器iis+php+mysq 环境,遇到了很多问题,特此就在这里说一下.小弟只是在windwos2003 和windwos XP下配置过iis+php+mysql,去朋友那 ...
- MVC4 WebAPI(二)——Web API工作方式
http://www.cnblogs.com/wk1234/archive/2012/05/07/2486872.html 在上篇文章中和大家一起学习了建立基本的WebAPI应用,立刻就有人想到了一些 ...
- js为DIV动态设置id属性
<script> var objs=document.getElementById("iproduct").getElementsByTagName("div ...
- (转)[SQL Server] 动态sql给变量赋值(或返回值给变量)
本文转载自:http://blog.csdn.net/xiaoxu0123/article/details/5684680 [SQL Server] 动态sql给变量赋值(或返回值给变量) decla ...
- 【JdbcTemplete】JdbcTemplete代码详解--模板方法详解
JdbcTemplete类层次结构 JdbcAccessor:对DataSource数据源进行管理和配置: JdbcOperations:定义了通过JDBC操作数据库的基本操作方法: JdbcTemp ...
- 查看CentOS版本方法
查看内核版本 这个命令适用于所有的linux,包括Redhat.SuSE.Debian.Centos等发行版. root@MyMail ~ # uname Linux root@MyMail ~ # ...