poj 1007 DNA Sorting
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 95437 | Accepted: 38399 |
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
Output
Sample Input
10 6
AACATGAAGG
TTTTGGCCAA
TTTGGCCAAA
GATCAGATTT
CCCGGGGGGA
ATCGATGCAT
Sample Output
CCCGGGGGGA
AACATGAAGG
GATCAGATTT
ATCGATGCAT
TTTTGGCCAA
TTTGGCCAAA 题目大意:根据字符串的逆序数,从小到大输出字符串。
思路:将字符串和它的逆序数联系起来,通过对它的逆序数从小到大排序,对字符串排序。。。用结构体解决,用sort函数排序。
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; typedef struct{
char s[];
int num;
}DNA; //求一个字符串的逆序数
int InversionNumber(char *s, int n){
int num = ;
for(int i = ; i < n - ; i++)
for(int j = i + ; j < n; j++){
if(s[i] > s[j])
num++;
}
return num;
} bool cmp(DNA a, DNA b){
return a.num < b.num;
} int main(){
int n, m;
cin >> n >> m;
DNA *a = new DNA [m];
for(int i = ; i < m; i++){
cin >> a[i].s;
a[i].num = InversionNumber(a[i].s, n);
}
sort(a, a + m, cmp); for(int i = ; i < m; i++)
cout << a[i].s << endl;
return ;
}
poj 1007 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 (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(sort函数的使用)
Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...
- 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 ...
随机推荐
- MySQL事务之数据结构
事务是关系型数据库的核心,贯穿整个源代码,先来瞅瞅相关的数据结构,揭开面纱: server层和innodb引擎层分别对应了不同的数据结构,但相互关联: server层需要引擎注册事务,以便server ...
- Cookie的Domain
每个Cookie都有常用的几个元素:name.value.expires.domain Cookie的Domain 设置cookies时,可以设置cookie的域名参数domain,标识cookie在 ...
- [转]ASP.NET MVC 入门3、Routing
在一个route中,通过在大括号中放一个占位符来定义( { and } ).当解析URL的时候,符号"/"和"."被作为一个定义符来解析,而定义符之间的值则匹配 ...
- HashPasswordForStoringInConfigFile 已过时
在.net 4.5版本下,使用System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile进行MD5加密时,会出 ...
- 【CSS3】Advanced9:Transformation
1.transform:rotate(-10deg) skew(20deg,10deg) scaling(2/1,2) translate/移动(100px,200px) 2.transform:ma ...
- JDK1.5新特性(二)……Static Import
援引 Static Import - This facility lets you avoid qualifying static members with class names without t ...
- HW2.14
import java.util.Scanner; public class Solution { public static void main(String[] args) { final dou ...
- javascript获取元素的计算样式
使用css控制页面有4种方式,分别为行内样式(内联样式).内嵌式.链接式.导入式. 行内样式(内联样式)即写在html标签中的style属性中,如<div style="width:1 ...
- jquery中链式操作的this指向
jquery中链式操作是如何实现? 例如:$(obj).children().css('color','red').next().css('color','red').siblings().css(' ...
- Hibernate拦截器(Interceptor)与事件监听器(Listener)
拦截器(Intercept):与Struts2的拦截器机制基本一样,都是一个操作穿过一层层拦截器,每穿过一个拦截器就会触发相应拦截器的事件做预处理或善后处理. 监听器(Listener):其实功能与拦 ...