算法:POJ1007 DNA sorting

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

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);
}
}
}
上一篇:com.alibaba.fastjson.JSONException: exepct '[', but {,


下一篇:cocos2dx 2.x实现闪电效果(贴画版)