关于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的更多相关文章

  1. [POJ 1007] DNA Sorting C++解题

        DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 77786   Accepted: 31201 ...

  2. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  3. [POJ] #1007# DNA Sorting : 桶排序

    一. 题目 DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95052   Accepted: 382 ...

  4. poj 1007 DNA Sorting

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95437   Accepted: 38399 Des ...

  5. poj 1007 DNA sorting (qsort)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 95209   Accepted: 38311 Des ...

  6. poj 1007 DNA Sorting 解题报告

    题目链接:http://poj.org/problem?id=1007 本题属于字符串排序问题.思路很简单,把每行的字符串和该行字符串统计出的字母逆序的总和看成一个结构体.最后把全部行按照这个总和从小 ...

  7. POJ 1007 DNA Sorting(sort函数的使用)

    Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...

  8. POJ 1007 DNA sorting (关于字符串和排序的水题)

    #include<iostream>//写字符串的题目可以用这种方式:str[i][j] &str[i] using namespace std; int main() {int ...

  9. DNA Sorting 分类: POJ 2015-06-23 20:24 9人阅读 评论(0) 收藏

    DNA Sorting Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 88690 Accepted: 35644 Descrip ...

随机推荐

  1. Linux 模块管理

    查看模块信息 modinfo module-name 加载模块 insmod module-name 卸载模块 rmmod module-name 生成模块依赖 cd /lib/module/`una ...

  2. DB2锁机制

    相比较Oracle来说,DB2的锁机制麻烦了很多,而且这个麻烦带来的不是性能的上升而是下降,不过如果细致了解的话,只能感慨不愧是数据库理论诞生的公司,在实现数据库理论上比Oracle全面得多.    ...

  3. c++之boost share_ptr

    转载:https://www.cnblogs.com/welkinwalker/archive/2011/10/20/2218804.html

  4. eclipse 远程调试mapreduce

    使用环境:centos6.5+eclipse(4.4.2)+hadoop2.7.0 1.下载eclipse hadoop 插件  hadoop-eclipse-plugin-2.7.0.jar 粘贴到 ...

  5. python之基础补充

    一 bit,和bytes的关系 bit:就是计算机的最小的表示单位. bytes:就是计算机的最小的储存单位. 1  字节(bytes) = 8 位(bit) 格式: print(bytes('字符' ...

  6. 优秀前端工程师必备:" checkbox & radio--单钩 & 多钩 "大比较:你是♂||♀ , 还是 ♂&♀

    1 单选: type="radio"  需求: 男女input只能选择一个 <input type="radio" name="sex" ...

  7. python编码(四)

    一.预备知识 字符集 1, 常用字符集分类 ASCII及其扩展字符集作用:表语英语及西欧语言.位数:ASCII是用7位表示的,能表示128个字符:其扩展使用8位表示,表示256个字符.范围:ASCII ...

  8. Spring bean加载2--FactoryBean情况处理

    Spring bean加载2--FactoryBean情况处理 在Spring bean加载过程中,每次bean实例在返回前都会调用getObjectForBeanInstance来处理Factory ...

  9. 2015 - 4- 21 iOS开发越狱环境的搭建1

    2015 - 4- 20   1. 越狱环境的搭建   http://www.iduuke.com/2030.html http://www.cnblogs.com/xiongwj0910/archi ...

  10. post异步请求

    //创建url NSURL *url = [[NSURL alloc] initWithString:@"http://api.hudong.com/iphonexml.do"]; ...