码迷,mamicode.com
首页 > 编程语言 > 详细

算法:POJ1007 DNA sorting

时间:2014-11-05 21:19:44      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   java   for   sp   div   

 

这题比较简单,重点应该在如何减少循环次数。

 

package practice;

import java.io.BufferedInputStream;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 * DNA sorting
 * 
 * @author caiyu
 * @date 2014-11-5
 */
public class POJ1007 {
    public static void main(String[] args) {
        Scanner cin = new Scanner(new BufferedInputStream(System.in));
        int l = cin.nextInt();
        int t = cin.nextInt();

        String s;
        Map<Integer, String> m = new TreeMap<Integer, String>();
        for (int i = 0; i < t; i++) {
            s = cin.next();
            int[] count = new int[l];
            int inversion = 0;
            for (int j = 0, len = l - 1; j < len; j++) {
                count[j] = s.charAt(j);
                for (int h = 0; h < j; h++) {
                    if (count[h] > count[j])
                        inversion++;
                }
            }
            m.put(inversion, s);
        }

        for (String x : m.values()) {
            System.out.println(x);
        }
    }
}

 

算法:POJ1007 DNA sorting

标签:style   blog   io   color   ar   java   for   sp   div   

原文地址:http://www.cnblogs.com/anrainie/p/4077306.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!