Created
April 20, 2013 23:32
-
-
Save khoatle/5427835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class DNASorting { | |
public static class DNA implements Comparable { | |
String dna; | |
public DNA(String str) { | |
dna = str; | |
} | |
public int compareTo(Object o) { | |
return score() - ((DNA) o).score(); | |
} | |
public int score() { | |
int score = 0; | |
for(int i = 0; i < dna.length(); i++) { | |
for(int j = i + 1; j < dna.length(); j++) { | |
if(dna.charAt(j) < dna.charAt(i)) { | |
score++; | |
} | |
} | |
} | |
return score; | |
} | |
} | |
public static void main(String args[]) { | |
// | |
Scanner scanner = new Scanner(System.in); | |
String tokens[] = scanner.nextLine().split(" "); | |
int L = Integer.parseInt(tokens[0]); | |
int T = Integer.parseInt(tokens[1]); | |
List<DNA> dnaList = new ArrayList<DNA>(); | |
for(int i = 0; i < T; i++) { | |
dnaList.add(new DNA(scanner.nextLine())); | |
} | |
Collections.sort(dnaList); | |
for(DNA dna : dnaList) { | |
System.out.println(dna.dna); | |
} | |
// System.out.println(new DNA("AACEDGG").score()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment