poj 1007 DNA sorting (qsort)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 95209 | Accepted: 38311 |
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
C/C++代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h> struct Str{
char str[];
int inversions;
}data[]; int inversionNumber(char s[]) { int len = strlen(s);
int result = ;
int A = , C = , G = ;
int i = len - ;
for(; i >= ; i--)
switch (s[i]) {
case 'A':
A++;
break;
case 'C':
result += A;
C++;
break;
case 'G':
result = result + A + C;
G++;
break;
case 'T':
result = result + A + C + G;
break;
}
return result;
} int cmp(const void * a, const void * b) { struct Str* c = (struct Str *)a;
struct Str* d = (struct Str *)b;
return c->inversions - d->inversions; } int main(int argc, const char * argv[]) { int length, number;
int i;
scanf("%d%d", &length, &number); for (i = ; i < number; i ++) {
scanf("%s", data[i].str);
data[i].inversions = inversionNumber(data[i].str);
} qsort(data, number, sizeof(data[]), cmp); for (i = ; i < number; i ++) {
printf("%s\n", data[i].str);
} return ;
}
poj 1007 DNA sorting (qsort)的更多相关文章
- poj 1007:DNA Sorting(水题,字符串逆序数排序)
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 80832 Accepted: 32533 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: 95052 Accepted: 382 ...
- poj 1007 DNA Sorting
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 95437 Accepted: 38399 Des ...
- 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 1007 DNA Sorting 解题报告
题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...
- 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 ...
随机推荐
- 在发布ASP.NET网站的时候,出现state server错误
错误信息如下: 在发布ASP.NET网站的时候,出现state server错误: Server Error in '/' Application. ------------------------- ...
- 【Linux】【四】linux 删除文件
1.rm -f * 删除当前目录下的文件 application/file/test/tools/logs/ #最经典的方法,删除当前目录下的所有类型的文件 2.rm -rf /ro ...
- jdk1.8-ArrayDeque
一:类的继承关系 UML图 类的继承关系: )))))) ]) & ()) == ) & ()) == ) & ()] = e) ) & (); return resu ...
- JavaScript基本入门03
目录 JavaScript 入门基础 03 JavaScript构造函数 常用事件和事件处理函数 小练习 数据类型之间的差异性 数组 介绍 创建 数组的常规使用 数组的length属性 数组当中常见的 ...
- C# 创建桌面快捷方式 用法
项目--->添加引用 找到 头部 using IWshRuntimeLibrary; 核心代码 string desktoppath = System.Environment.GetFold ...
- linux(centos7)下SVN服务器搭建
https://www.cnblogs.com/fuyuanming/p/6123395.html linux(centos)下SVN服务器如何搭建?说到SVN服务器,想必大家都知道,可以是在LINU ...
- 【神经网络与深度学习】ZLIB介绍
zlib类库提供了很多种压缩和解压缩的方式,由于时间的关系我只学习一下内容,以下是我在实现web 服务器压缩数据网页中使用到一些函数和常用数据结构.常量等. zlib使用过程 压缩过程:deflate ...
- so的封装和使用
背景 在linux平台下,要实现函数的封装,一般采用的是so动态库的形式 实现了函数的封装就意味着实现过程的隐藏 可以实现跨平台和跨语言的使用 实施步骤 生成so动态库 编写相应的c文件代码,实现函数 ...
- Array js扩展方法 forEach()
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Hive怎么使用远程连接
HIVE的连接模式== 本地连接模式 直接启动hive命令 HIVE的远程连接 这里要启动HIVE的服务 thirft进行编写 hiveserver2 —- > 前台启动 后台启动 前台启动 h ...