关于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. 如何在C#中自定义自己的异常

    在C#中所有的异常类型都继承自System.Exception,也就是说,System.Exception是所有异常类的基类. 总起来说,其派生类分为两种:1. SystemException类: 所 ...

  2. 学习socket的小例子

    /************************************************************** 技术博客 http://www.cnblogs.com/itdef/   ...

  3. sklearn 算法大全

    http://scikit-learn.org/stable/tutorial/machine_learning_map/

  4. python panda库自动去重

    http://blog.csdn.net/xinxing__8185/article/details/48022401

  5. http mimetype为multipart/x-mixed-replace报文

    http://blog.csdn.net/gmstart/article/details/7064034 服务器推送(Server Push) 推送技术的基础思想是将浏览器主动查询信息改为服务器主动发 ...

  6. 2018.09.23 codeforces 1053B. Vasya and Good Sequences(前缀和)

    传送门 考试的时候卡了一会儿. 显然这个答案只跟二进制位为1的数量有关. 还有一个显然的结论. 对于一个区间[l,r][l,r][l,r],如果其中单个数二进制位为1的数量最大值不到区间所有数二进制位 ...

  7. 2018.09.11 bzoj47214721: [Noip2016]蚯蚓(单调队列)

    传送门 好题. 目测只会多带一个log2(n+m)" role="presentation" style="position: relative;"& ...

  8. Java生成HTML文件

    实例HTML文件<html> <head> <title>###title###</title> <meta http-equiv="C ...

  9. b2_trsd_EDSD_new

    # -*- coding:utf-8 -*- import re ss="./data/" year = '17A' filename = ss+'EDSD%s.txt'%year ...

  10. day4之装饰器进阶、生成器迭代器

    装饰器进阶 带参数的装饰器 # 某一种情况# 500个函数加装饰器, 加完后不想再加这个装饰器, 再过一个季度,又想加上去# 你可以设计你的装饰器,来确认是否执行 # 第一种情况 # 想要500个函数 ...