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 ...
随机推荐
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
为什么会想起来将上传的word文档转换成html格式呢?设想,如果一个系统需要发布在页面的文章都是来自word文档,一般会执行下面的流程:使用word打开文档,Ctrl+A,进入发布文章页面,Ctrl ...
- SQL开发利器SQL Prompt
SQL开发利器SQL Prompt 5.1完全破解+使用教程 - keepfool - 博客园 http://www.cnblogs.com/keepfool/archive/2012/05/27/2 ...
- android 为应用程序创建桌面快捷方式技巧分享
手机装的软件过多,找起来很不方便,所以在主页面有一个快捷方式的话会很不错的,本文将介绍如何实现,需要了解跟多的朋友可以参考下 我们开发一款软件后,如果手机装的软件过多,去翻的话会很难翻的,所以 ...
- python主要用来做什么
python这门编程语言在国外极受欢迎,但在国内使用还不是极普遍. 由于python编程效率极高,现在国内的使用者也开始变得越来越多. python主要用来做什么?这个语言到底有哪些作用呢? 下面主是 ...
- Remove LUN from OCFS2
# ocfs2_hb_ctl -I -d /dev/mapper/backup2-backup2 508C2154503344E78ACD6CD6B000000: 2 refs #The previo ...
- golang的ssh例子
package main import ( "github.com/dynport/gossh" "log" ) func MakeLogger(prefix ...
- 报错:org.apache.jasper.JasperException: /index.jsp (line: 1, column: 17) equal symbol expected
现象:写了如下一个jsp文件,导入需要用到的两个包: 运行结果报错:org.apache.jasper.JasperException: /index.jsp (line: 1, column: 17 ...
- Wordpress-数据库结构分析(转)
之前用了一段时间的Wordpress,觉得真的是一个优秀的博客系统,而且有大量的主题和插件.是我目前用过的最棒的一个博客平台.不仅如此,Wordpress 的代码也是写得非常漂亮,很适合用来学习PHP ...
- java.lang.ClassNotFoundException: org.eclipse.jetty.plus.webapp.EnvConfiguration
最近刚接触jetty,在myeclipse8.6中加入了一个项目,运行时就出了这个java.lang.ClassNotFoundException: org.eclipse.jetty.plus.we ...
- 手势识别(一)--手势基本概念和ChaLearn Gesture Challenge
以下转自: http://blog.csdn.net/qq1175421841/article/details/50312565 像点击(clicks)是GUI平台的核心,轻点(taps)是触摸平台的 ...