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 ...
随机推荐
-
Trasformation中的公式报错误,错误数据行定位
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
-
Users is not mapped(Hibernate实体类采用注解)
今天做简单的登陆验证web应用时,用HQL语句查询数据表时 总是出现Users is not mapped [from Users u where u.username=? and u.passwor ...
-
自定义php错误异常处理
set_exception_handler() 函数设置用户自定义的异常处理函数. 该函数用于创建运行时期间的用户自己的异常处理方法. 该函数会返回旧的异常处理程序,若失败,则返回 null. set ...
-
JavaScript之基础语法整理
1.数据类型(number,boolean,string,null,undefined,symbol,object) es是动态语言,弱类型语言,虽然先声明了变量,但是变量可以重新赋值任意类型 弱类型 ...
-
Android Service解析
Android Service是一个可以在后台执行长时间运行操作而不提供用户界面的应用组件,它分为两种工作状态,一种是启动状态,主要用于执行后台计算:另一种是绑定状态,主要用于其他组件和Service ...
-
C语言强化——链表(2)
目录 链表的应用: 栈 循环队列 C语言实现动态数组 数组实现定长元素个数层次建树 队列实现不定元素个数层次建树 (*) 栈 栈(链表应用) "stack.h" #include ...
-
js 操作数字类型
1.内置函数 Number().parseInt().parseFloat() var num = "88.88abc888"; Number(num); ...
-
WebUploader在IE9中文件选择按钮点击没反应
一.问题: 最近做的公司项目里,用户环境一直用的火狐,但是实际的用户群体都是银行人员 *部门怎么也要用 IE,而且还有一些用的IE版本是古董版本IE9 IE9 相比 IE8 多了图像渲染等,无法兼容 ...
-
[HAOI2006]旅行 题解(kruskal)
[HAOI2006]旅行 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N个景点(编号为1,2,3,-,N),这些景点被M条道路连接着,所有道路都 ...
-
CanvasRenderingContext2D.lineDashOffset
https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset CanvasRende ...