package main_java import java util Arrays public class Main public sta

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main_java;
import java.util.Arrays;
public class Main {
public static class Lab implements Comparable<Lab> {
private char[] s;
private int count;
private int count() {
int c = 0;
for(char x : s)
if(x == 'a')
c++;
return c;
}
public Lab(char[] s) {
this.s = s;
count = count();
}
public String toString() {
String res = "";
for(char x : s)
res += x;
return res;
}
public int compareTo(Lab obj) {
return count - obj.count; // code
}
}
public static void main(String[] args) {
Lab[] a = new Lab[] { new Lab(new char[] {'a', 'a', 'c'}), new Lab(new char[] {'b', 'd', 'c'}), new Lab(new char[] {'b', 'a', 'c'})};
Arrays.sort(a);
for (Lab s : a)
System.out.println(s);
}
}