题解 | #记负均正#
字符统计
http://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNextLine()){
Map<Character, Integer> map = new HashMap<>();
String str = in.nextLine();
List<Character> list = new ArrayList<>();
for(char c:str.toCharArray()){
if(map.get(c) == null){
map.put(c, 1);
list.add(c);
} else {
map.put(c, map.get(c)+1);
}
}
Collections.sort(list, new Comparator<Character>(){
@Override
public int compare(Character c1, Character c2) {
return map.get(c1)!=map.get(c2)?
map.get(c2)-map.get(c1):
c1-c2;
}
});
for(char c:list){
System.out.print(c);
}
System.out.println();
}
}
}
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNextLine()){
Map<Character, Integer> map = new HashMap<>();
String str = in.nextLine();
List<Character> list = new ArrayList<>();
for(char c:str.toCharArray()){
if(map.get(c) == null){
map.put(c, 1);
list.add(c);
} else {
map.put(c, map.get(c)+1);
}
}
Collections.sort(list, new Comparator<Character>(){
@Override
public int compare(Character c1, Character c2) {
return map.get(c1)!=map.get(c2)?
map.get(c2)-map.get(c1):
c1-c2;
}
});
for(char c:list){
System.out.print(c);
}
System.out.println();
}
}
}