poj 107 DNA sorting
关于Java的题解,也许效率低下,但是能解决不只是ACGT的序列字符串
代码如下:
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
TreeMap<Integer,String> map = new TreeMap<Integer,String>();
//读入题目所给的信息
int n = sc.nextInt(),m = sc.nextInt(),count;
String[] strs = new String[m];
for(int i=0;i<strs.length;i++){
strs[i] = sc.next();
if(strs[i].length()!=n)
throw new RuntimeException();
}
//计算每一个序列的measure数,用count表示
for(int i=0;i<strs.length;i++){
count=0;
for(int j=0;j<strs[i].length()-1;j++){
for(int k=j+1;k<strs[i].length();k++){
char ch1 = strs[i].charAt(j);
char ch2 = strs[i].charAt(k);
if(ch1>ch2)
count++;
}
}
//如果发现序列中有相同的count,那么把该序列加到原序列的末尾,用来最后的输出
if(map.containsKey(count)){
String value = map.get(count);
map.put(count,value+strs[i]);
}
else
map.put(count, strs[i]);
}
//输出答案序列
for(Map.Entry<Integer, String> entry : map.entrySet()){
String value = entry.getValue();
int size = value.length()/n;
if(size>1){
int offset = 0;
for(int i=1;i<=size;i++){
System.out.println(value.substring(offset,offset+n));
offset+=n;
}
}
else
System.out.println(value);
}
}
}
poj 107 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 ...
- 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 ...
- DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏
DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...
随机推荐
- Linux tcpdump命令
一.简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据 ...
- 论坛遇到附件上传失败问题总结(discuz)
(1)bbs/source/class/class_upload.php 50行左右,注释$attach['target'] $attach['target'] = DISCUZ_ROOT.'./da ...
- OSGi 系列(十四)之 Event Admin Service
OSGi 系列(十四)之 Event Admin Service OSGi 的 Event Admin 服务规范提供了开发者基于发布/订阅模型,通过事件机制实现 Bundle 间协作的标准通讯方式. ...
- 8.15jsp document 头部声明 区别
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 7.20 文本框内容 超出 显示 。。 和 split
word-wrap:break-word; word-break:break-all; overflow:auto; split 去 :等 ,只要有: 就会在:两边 各生产一个值 ,所有 应习惯把最 ...
- DataStage 九、数据交换到MySQL以及乱码问题
DataStage序列文章 DataStage 一.安装 DataStage 二.InfoSphere Information Server进程的启动和停止 DataStage 三.配置ODBC Da ...
- C语言基础课第四次作业
1.实验代码 7-2 打印九九口诀表 (15 分) #include<stdio.h> #include<math.h> int main(void){ int a, ...
- KindEditor解决上传视频不能在手机端显示的问题
KindEditor自带的上传视频生成的HTML代码为<embed>,在手机端并不支持.于是可以自己在控件里增加生成video标签相关代码. 参考https://www.jianshu.c ...
- try-catch+thows异常范围说明
方式一: CatalogPO deleteTarget = null; /** 查询是否存在 **/ deleteTarget = catalogMapper.findByCatalogId(cata ...
- 破解Excel密码
https://zhidao.baidu.com/question/98055974.html 方法:1\打开文件2\工具---宏----录制新宏---输入名字如:aa3\停止录制(这样得到一个空宏) ...